Merge pull request #201 from ramielrowe/master
Handling case of no data in 0003 migration
This commit is contained in:
@@ -41,13 +41,14 @@ def queryset_iterator(queryset, chunksize=1000):
|
|||||||
Note that the implementation of the iterator does not support ordered query sets.
|
Note that the implementation of the iterator does not support ordered query sets.
|
||||||
'''
|
'''
|
||||||
id = 0
|
id = 0
|
||||||
last_pk = queryset.order_by('-id')[0]['id']
|
if queryset.order_by('-id').count() > 0:
|
||||||
queryset = queryset.order_by('id')
|
last_pk = queryset.order_by('-id')[0]['id']
|
||||||
while id < last_pk:
|
queryset = queryset.order_by('id')
|
||||||
for row in queryset.filter(id__gt=id)[:chunksize]:
|
while id < last_pk:
|
||||||
id = row['id']
|
for row in queryset.filter(id__gt=id)[:chunksize]:
|
||||||
yield row
|
id = row['id']
|
||||||
gc.collect()
|
yield row
|
||||||
|
gc.collect()
|
||||||
|
|
||||||
|
|
||||||
class Migration(DataMigration):
|
class Migration(DataMigration):
|
||||||
|
|||||||
Reference in New Issue
Block a user