diff options
| author | Simon Charette <charette.s@gmail.com> | 2016-08-20 16:34:06 -0400 |
|---|---|---|
| committer | Simon Charette <charette.s@gmail.com> | 2016-08-24 01:17:18 -0400 |
| commit | d1757d8df486b689172d2584ded52fad916bcc33 (patch) | |
| tree | 980ca1d049ea7743a95a81460181d81015160e50 /django | |
| parent | ad25fe73506d80ffcaac135ad0a8d09552b70d70 (diff) | |
Fixed #27044 -- Included already applied migration changes in the post-migrate state when the execution plan is empty.
Refs #24100.
Thanks tkhyn for the report and Tim for the review.
Diffstat (limited to 'django')
| -rw-r--r-- | django/core/management/commands/migrate.py | 12 | ||||
| -rw-r--r-- | django/db/migrations/executor.py | 10 |
2 files changed, 14 insertions, 8 deletions
diff --git a/django/core/management/commands/migrate.py b/django/core/management/commands/migrate.py index b6c8748bff..4c8e008374 100644 --- a/django/core/management/commands/migrate.py +++ b/django/core/management/commands/migrate.py @@ -175,7 +175,6 @@ class Command(BaseCommand): if self.verbosity >= 1: self.stdout.write(self.style.MIGRATE_HEADING("Running migrations:")) if not plan: - executor.check_replacements() if self.verbosity >= 1: self.stdout.write(" No migrations to apply.") # If there's changes that aren't in migrations yet, tell them how to fix it. @@ -194,14 +193,15 @@ class Command(BaseCommand): "migrations, and then re-run 'manage.py migrate' to " "apply them." )) - post_migrate_apps = pre_migrate_apps + fake = False + fake_initial = False else: fake = options['fake'] fake_initial = options['fake_initial'] - post_migrate_project_state = executor.migrate( - targets, plan, fake=fake, fake_initial=fake_initial - ) - post_migrate_apps = post_migrate_project_state.apps + post_migrate_project_state = executor.migrate( + targets, plan, fake=fake, fake_initial=fake_initial + ) + post_migrate_apps = post_migrate_project_state.apps # Re-render models of real apps to include relationships now that # we've got a final state. This wouldn't be necessary if real apps diff --git a/django/db/migrations/executor.py b/django/db/migrations/executor.py index fb9c7a93a4..11a96ec81b 100644 --- a/django/db/migrations/executor.py +++ b/django/db/migrations/executor.py @@ -82,9 +82,15 @@ class MigrationExecutor(object): all_backwards = all(backwards for mig, backwards in plan) if not plan: - # Nothing to do for an empty plan, except for building the post - # migrate project state + # The resulting state should include applied migrations. state = self._create_project_state() + applied_migrations = { + self.loader.graph.nodes[key] for key in self.loader.applied_migrations + if key in self.loader.graph.nodes + } + for migration, _ in full_plan: + if migration in applied_migrations: + migration.mutate_state(state, preserve=False) elif all_forwards == all_backwards: # This should only happen if there's a mixed plan raise InvalidMigrationPlan( |
