python - how to configure django to run migration files in a specific order -
i have project requires me insert initial data database on migration. works fine except need tell django insert specific data linked migration file before running another.
for example, lets have 2 migration files, , b, , each attached models modela , modelb respectively. migration works fine, b, automatically generating sql statement requires me use modela.objects.get(id=id)
while generating statements, error modela.doesnotexist
, means migration hasn't been saved.
is there way can ensure data inserted migration has been saved before proceeding run migration b?
as @tom-dalton mentioned way go through dependencies.
you can see example of dependency in migration file here in docs.
they written in following format:
from django.db import migrations, models class migration(migrations.migration): dependencies = [("your_app_name", "migration_file_name")] operations = [ # migration operations here ]
you can find migration file name looking in migrations folder of project.
finally need follow data migration process access modela data in new migration.
Comments
Post a Comment