summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Melchiorre <paolo@melchiorre.org>2017-03-27 20:07:11 +0200
committerTim Graham <timograham@gmail.com>2017-03-27 14:07:35 -0400
commite8f585440dce2730b08eda818eba166f9f9f4930 (patch)
tree9fa6fe4ef3c9cb2b8ae347b19a44edb72ba6fdf8
parent28cf32b2cb4e6385102be3192aea414be402e1a1 (diff)
[1.11.x] Made a few cosmetic updates to "Migrations that add unique fields".
Backport of 24d53786d414586bb56243758cec41e802e8947d from master
-rw-r--r--docs/howto/writing-migrations.txt10
1 files changed, 5 insertions, 5 deletions
diff --git a/docs/howto/writing-migrations.txt b/docs/howto/writing-migrations.txt
index 310d34474c..9465290c74 100644
--- a/docs/howto/writing-migrations.txt
+++ b/docs/howto/writing-migrations.txt
@@ -94,8 +94,8 @@ the respective field according to your needs.
give them meaningful names in the examples below.
* Copy the ``AddField`` operation from the auto-generated migration (the first
- of the three new files) to the last migration and change ``AddField`` to
- ``AlterField``. For example:
+ of the three new files) to the last migration, change ``AddField`` to
+ ``AlterField``, and add imports of ``uuid`` and ``models``. For example:
.. snippet::
:filename: 0006_remove_uuid_null.py
@@ -107,7 +107,6 @@ the respective field according to your needs.
from django.db import migrations, models
import uuid
-
class Migration(migrations.Migration):
dependencies = [
@@ -149,7 +148,8 @@ the respective field according to your needs.
* In the first empty migration file, add a
:class:`~django.db.migrations.operations.RunPython` or
:class:`~django.db.migrations.operations.RunSQL` operation to generate a
- unique value (UUID in the example) for each existing row. For example:
+ unique value (UUID in the example) for each existing row. Also add an import
+ of ``uuid``. For example:
.. snippet::
:filename: 0005_populate_uuid_values.py
@@ -165,7 +165,7 @@ the respective field according to your needs.
MyModel = apps.get_model('myapp', 'MyModel')
for row in MyModel.objects.all():
row.uuid = uuid.uuid4()
- row.save()
+ row.save(update_fields=['uuid'])
class Migration(migrations.Migration):