-
Notifications
You must be signed in to change notification settings - Fork 348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
run migrations on test database if --reuse-db is set #220
Conversation
FYI there's a |
@alvinchow86 Yeah I use that (in other projects) as well. In this project however I also got data migrations which are needed for the tests to succeed. |
Thanks for addressing this. My pet peeve is data migrations. Skipping migrations is problematic with data migrations, when this data is being used in tests. I've thought that this could be handled better by leaning more towards Django's internal methods, which I've started in #203. What do you think about that? As far as I can see, your method won't help with data migrations (when transactional_db is involved, and the db is flushed): the apps are being considered to be fully migrated already. A workaround is to use the
In this context it's also noteworthy that Django runs its tests in a particular order. I've started working to handle this in the same way for pytest-django, but it won't solve the data migration issue probably either (alone). |
Some more notes: using |
@blueyed your probably right. Does Django automatically rollup the migrations in your PR ? (without rerunning them ?) |
@trbs It is being discussed to add a warning / and/or abort in this case: https://code.djangoproject.com/ticket/24484 I think this PR is good as-is, but I'd like to have some tests for this, especially also in regard to the output that is being generated for different verbosity levels. |
This PR itself (running The issue about keeping your data from the migrations seems still not be solvable in a straight-forward way.. :/ |
database=self.connection.alias, | ||
run_syncdb=True, | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The command in Django 1.8 looks a bit different: https://github.com/django/django/blob/stable/1.8.x/django/db/backends/base/creation.py#L360-L369:
call_command(
'migrate',
verbosity=max(verbosity - 1, 0),
interactive=False,
database=self.connection.alias,
test_flush=not keepdb,
)
What do you think about using #261 (Django's --keepdb
), which would cover Django 1.8+, and then this for Django 1.7.x?
I think this should be covered by 0ec741b since a while, where we're using Django's method for 1.5+ now. Please re-open in case I'm wrong. |
Run migrations on the test database(s) when
--reuse-db
options is enabled and the test database already exists.This helps people with large (and slow) migration sets which otherwise would have to drop the test database or manually run the migrations on it.