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
4283a038
Kaydet (Commit)
4283a038
authored
Eyl 09, 2015
tarafından
Bibhas
Kaydeden (comit)
Tim Graham
Eyl 09, 2015
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #25371 -- Added reverse_sql and reverse_code examples to docs.
üst
dae81c6e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
3 deletions
+21
-3
migration-operations.txt
docs/ref/migration-operations.txt
+21
-3
No files found.
docs/ref/migration-operations.txt
Dosyayı görüntüle @
4283a038
...
...
@@ -224,6 +224,14 @@ queries and parameters in the same way as :ref:`cursor.execute()
If you want to include literal percent signs in the query, you have to double
them if you are passing parameters.
The ``reverse_sql`` queries are executed when the migration is unapplied, so
you can reverse the changes done in the forwards queries::
migrations.RunSQL(
["INSERT INTO musician (name) VALUES (%s);", ['Reinhardt']],
["DELETE FROM musician where name=%s;", ['Reinhardt']],
)
The ``state_operations`` argument is so you can supply operations that are
equivalent to the SQL in terms of project state; for example, if you are
manually creating a column, you should pass in a list containing an ``AddField``
...
...
@@ -265,6 +273,10 @@ match the operation's place in the project history, and the second is an
instance of :class:`SchemaEditor
<django.db.backends.base.schema.BaseDatabaseSchemaEditor>`.
The ``reverse_code`` argument is called when unapplying migrations. This
callable should undo what is done in the ``code`` callable so that the
migration is reversible.
The optional ``hints`` argument will be passed as ``**hints`` to the
:meth:`allow_migrate` method of database routers to assist them in making a
routing decision. See :ref:`topics-db-multi-db-hints` for more details on
...
...
@@ -294,14 +306,20 @@ model::
Country(name="France", code="fr"),
])
def reverse_func(apps, schema_editor):
# forwards_func() creates two Country instances,
# so reverse_func() should delete them.
Country = apps.get_model("myapp", "Country")
db_alias = schema_editor.connection.alias
Country.objects.using(db_alias).filter(name="USA", code="us").delete()
Country.objects.using(db_alias).filter(name="France", code="fr").delete()
class Migration(migrations.Migration):
dependencies = []
operations = [
migrations.RunPython(
forwards_func,
),
migrations.RunPython(forwards_func, reverse_func),
]
This is generally the operation you would use to create
...
...
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