runpython django migration

Solutions on MaxInterview for runpython django migration by the best coders in the world

showing results for - "runpython django migration"
Elina
21 Feb 2019
1from django.db import migrations
2
3def forwards_func(apps, schema_editor):
4    # We get the model from the versioned app registry;
5    # if we directly import it, it'll be the wrong version
6    Country = apps.get_model("myapp", "Country")
7    db_alias = schema_editor.connection.alias
8    Country.objects.using(db_alias).bulk_create([
9        Country(name="USA", code="us"),
10        Country(name="France", code="fr"),
11    ])
12
13def reverse_func(apps, schema_editor):
14    # forwards_func() creates two Country instances,
15    # so reverse_func() should delete them.
16    Country = apps.get_model("myapp", "Country")
17    db_alias = schema_editor.connection.alias
18    Country.objects.using(db_alias).filter(name="USA", code="us").delete()
19    Country.objects.using(db_alias).filter(name="France", code="fr").delete()
20
21class Migration(migrations.Migration):
22
23    dependencies = []
24
25    operations = [
26        migrations.RunPython(forwards_func, reverse_func),
27    ]
28
queries leading to this page
rerun migrations djangopython django migrationpython database migrationsdjango migrations rpythoncall django manae py command in migration scripthow to run python manage py migratedjango migration runpythonpython manage py migrationmigrations runpython djangorun python file with djangopython run migrationsdjango rundjango run command in migration python manage py migrations how to run python script in djangodjango run migrations commanddjango custom migration runpythondjango python migratepython django migration update modeldjango migration run commanddjango run python script in projectdjango migrations do pythondjango create migration scripts from databasemigration pythonpython django migrateexecute python script djangorun database migration djangohow to run migration on database djangoimport latest migration djangopython migrationspython make migrationpython django migrate pydjango python manage py migratewhere should a python script be run in djangodjango migrations runpython new fielddjango how to run migrationsdjango run migrationsrun python in djangodjango run a migrationpython manage py migrationsdjango migrations runpythonrunpython django migrationdjango run initial migrationdjango run code inside migrationhow to run python django coderun migration djangodjago migration run pythonpython run djangopython migrationexecute django command from migrationrun initial migration again djangopython manage run migrationspython poertry run django make migrationsrunpython django migration