@@ -94,8 +94,8 @@ the respective field according to your needs.
9494 give them meaningful names in the examples below.
9595
9696* Copy the ``AddField`` operation from the auto-generated migration (the first
97- of the three new files) to the last migration and change ``AddField`` to
98- ``AlterField``. For example:
97+ of the three new files) to the last migration, change ``AddField`` to
98+ ``AlterField``, and add imports of ``uuid`` and ``models`` . For example:
9999
100100 .. snippet::
101101 :filename: 0006_remove_uuid_null.py
@@ -104,7 +104,6 @@ the respective field according to your needs.
104104 from django.db import migrations, models
105105 import uuid
106106
107-
108107 class Migration(migrations.Migration):
109108
110109 dependencies = [
@@ -146,7 +145,8 @@ the respective field according to your needs.
146145* In the first empty migration file, add a
147146 :class:`~django.db.migrations.operations.RunPython` or
148147 :class:`~django.db.migrations.operations.RunSQL` operation to generate a
149- unique value (UUID in the example) for each existing row. For example:
148+ unique value (UUID in the example) for each existing row. Also add an import
149+ of ``uuid``. For example:
150150
151151 .. snippet::
152152 :filename: 0005_populate_uuid_values.py
@@ -159,7 +159,7 @@ the respective field according to your needs.
159159 MyModel = apps.get_model('myapp', 'MyModel')
160160 for row in MyModel.objects.all():
161161 row.uuid = uuid.uuid4()
162- row.save()
162+ row.save(update_fields=['uuid'] )
163163
164164 class Migration(migrations.Migration):
165165
0 commit comments