I have several apps in my Django 2.0.2 project. One of the apps (app_one) has a migration that depends on migrations from the other app (app_two) being installed. It is initial migration of app_one and it looks like this:
def import_data(apps, schema_editor):
schema_model = apps.get_model('app_two', 'Model')
# do import
def drop_data(apps, schema_editor):
schema_model = apps.get_model('app_two', 'Model')
# undo import
class Migration(migrations.Migration):
dependencies = [
('app_two', '0005_auto_20180127_2155')
]
operations = [
migrations.RunPython(
import_data,
reverse_code=drop_data
)
]
Currently in order to install the database I need to manage.py migrate app_two and only after that do manage.py migrate, because otherwise I get an error on this migration that relation Model from app_two does not exist. Also I'm unable to run tests manage.py test normally due to the same error. It seems that Django ignores dependency in this migration for some reason. How do I fix that?
Check out the docs about ordering your migrations:
https://docs.djangoproject.com/en/2.0/howto/writing-migrations/#controlling-the-order-of-migrations
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With