1 year ago
#386235
TCFDS
Django migrations: base data with tests
I am adding some base data to database with Django's database migrations. Base data consists of predefined values of types which are accessible to all users. There is also possibility to create custom types by users.
Problem is that when running tests with --keepdb
option, tables will be flushed and also base data will be removed. Without --keepdb
option tests are considerably slower.
Is there a way to create base data so that it would be available to tests with --keepdb
option? Or is there a way to run tests so that base data would be accessible without doing all migrations again?
Migrations I have created look like this:
def set_default_values(apps, schema_editor):
Type = apps.get_model('app1', 'Type')
Type(name='name1', user=None).save()
Type(name='name2', user=None).save()
Type(name='name3', user=None).save()
class Migration(migrations.Migration):
# ...
operations = [
migrations.RunPython(set_default_values, elidable=True)
]
django
django-migrations
django-tests
0 Answers
Your Answer