Skip to content

run migrations on test database if --reuse-db is set #220

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pytest_django/db_reuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ def create_test_db_with_reuse(self, verbosity=1, autoclobber=False,
will not actually create a new database, but just reuse the
existing.
"""
from django import VERSION as DJANGO_VERSION
from django.core.management import call_command

test_database_name = self._get_test_db_name()
self.connection.settings_dict['NAME'] = test_database_name

Expand All @@ -111,6 +114,15 @@ def create_test_db_with_reuse(self, verbosity=1, autoclobber=False,
if hasattr(self.connection.features, 'confirm'):
self.connection.features.confirm()

if DJANGO_VERSION > (1, 7):
call_command(
'migrate',
verbosity=max(verbosity - 1, 0),
interactive=False,
database=self.connection.alias,
run_syncdb=True,
)

Copy link
Contributor

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?

return test_database_name


Expand Down