I have an app with a fair number of migrations including data migrations to set foreign keys on some models.
When I try to run tests.py, it fails because the data migration is querying the database for data that doesn't exist in the test database.
Is there a way to disable the data migrations? (I want to keep schema migrations, not disable migrations completely).
Or alternatively to load data from fixtures before running the data migrations?
For check either test are running or not:
'test' in sys.argv
I was inspired by Disable migrations while testing and @A. Grinenko. I did not customize TestRunner and I just checked whether 0002_data_migration.py
was called by django test.
code:
class Migration(migrations.Migration):
dependencies = [
('backend', '0001_initial'),
]
operations = [
migrations.RunPython(setup_data, rollback_setup, atomic=True)
] if 'test' not in sys.argv[1:] else []
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