Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
24d53786
Kaydet (Commit)
24d53786
authored
Mar 27, 2017
tarafından
Paolo Melchiorre
Kaydeden (comit)
Tim Graham
Mar 27, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Made a few cosmetic updates to "Migrations that add unique fields".
üst
ed0cbc8d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
5 deletions
+5
-5
writing-migrations.txt
docs/howto/writing-migrations.txt
+5
-5
No files found.
docs/howto/writing-migrations.txt
Dosyayı görüntüle @
24d53786
...
@@ -94,8 +94,8 @@ the respective field according to your needs.
...
@@ -94,8 +94,8 @@ the respective field according to your needs.
give them meaningful names in the examples below.
give them meaningful names in the examples below.
* Copy the ``AddField`` operation from the auto-generated migration (the first
* Copy the ``AddField`` operation from the auto-generated migration (the first
of the three new files) to the last migration
and
change ``AddField`` to
of the three new files) to the last migration
,
change ``AddField`` to
``AlterField``. For example:
``AlterField``
, and add imports of ``uuid`` and ``models``
. For example:
.. snippet::
.. snippet::
:filename: 0006_remove_uuid_null.py
:filename: 0006_remove_uuid_null.py
...
@@ -104,7 +104,6 @@ the respective field according to your needs.
...
@@ -104,7 +104,6 @@ the respective field according to your needs.
from django.db import migrations, models
from django.db import migrations, models
import uuid
import uuid
class Migration(migrations.Migration):
class Migration(migrations.Migration):
dependencies = [
dependencies = [
...
@@ -146,7 +145,8 @@ the respective field according to your needs.
...
@@ -146,7 +145,8 @@ the respective field according to your needs.
* In the first empty migration file, add a
* In the first empty migration file, add a
:class:`~django.db.migrations.operations.RunPython` or
:class:`~django.db.migrations.operations.RunPython` or
:class:`~django.db.migrations.operations.RunSQL` operation to generate a
: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::
.. snippet::
:filename: 0005_populate_uuid_values.py
:filename: 0005_populate_uuid_values.py
...
@@ -159,7 +159,7 @@ the respective field according to your needs.
...
@@ -159,7 +159,7 @@ the respective field according to your needs.
MyModel = apps.get_model('myapp', 'MyModel')
MyModel = apps.get_model('myapp', 'MyModel')
for row in MyModel.objects.all():
for row in MyModel.objects.all():
row.uuid = uuid.uuid4()
row.uuid = uuid.uuid4()
row.save()
row.save(
update_fields=['uuid']
)
class Migration(migrations.Migration):
class Migration(migrations.Migration):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment