diff options
| author | Markus Holtermann <info@markusholtermann.eu> | 2015-02-12 12:48:28 +0100 |
|---|---|---|
| committer | Markus Holtermann <info@markusholtermann.eu> | 2015-02-13 15:21:10 +0100 |
| commit | bd80fa6b0f7e5a0cc4ea26cedd56d0c4c4894420 (patch) | |
| tree | 8ce4c4f1532fe8c177115eca6714096247bcae16 /django/db/migrations/executor.py | |
| parent | 4ba7d73f94b47abfb5f90ac223973bcd64466e80 (diff) | |
[1.8.x] Fixed #24184 -- Prevented automatic soft-apply of migrations
Previously Django only checked for the table name in CreateModel
operations in initial migrations and faked the migration automatically.
This led to various errors and unexpected behavior. The newly introduced
--fake-initial flag to the migrate command must be passed to get the
same behavior again. With this change Django will bail out in with a
"duplicate relation / table" error instead.
Thanks Carl Meyer and Tim Graham for the documentation update, report
and review.
Backport of f287bec5833d75750fa6368bc2802741b7924533 from master
Diffstat (limited to 'django/db/migrations/executor.py')
| -rw-r--r-- | django/db/migrations/executor.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/django/db/migrations/executor.py b/django/db/migrations/executor.py index 8a55ed0d69..d1a8dd64dc 100644 --- a/django/db/migrations/executor.py +++ b/django/db/migrations/executor.py @@ -62,7 +62,7 @@ class MigrationExecutor(object): applied.add(migration) return plan - def migrate(self, targets, plan=None, fake=False): + def migrate(self, targets, plan=None, fake=False, fake_initial=False): """ Migrates the database up to the given targets. @@ -91,7 +91,7 @@ class MigrationExecutor(object): # Phase 2 -- Run the migrations for migration, backwards in plan: if not backwards: - self.apply_migration(states[migration], migration, fake=fake) + self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial) else: self.unapply_migration(states[migration], migration, fake=fake) @@ -113,18 +113,19 @@ class MigrationExecutor(object): statements.extend(schema_editor.collected_sql) return statements - def apply_migration(self, state, migration, fake=False): + def apply_migration(self, state, migration, fake=False, fake_initial=False): """ Runs a migration forwards. """ if self.progress_callback: self.progress_callback("apply_start", migration, fake) if not fake: - # Test to see if this is an already-applied initial migration - applied, state = self.detect_soft_applied(state, migration) - if applied: - fake = True - else: + if fake_initial: + # Test to see if this is an already-applied initial migration + applied, state = self.detect_soft_applied(state, migration) + if applied: + fake = True + if not fake: # Alright, do it normally with self.connection.schema_editor() as schema_editor: state = migration.apply(state, schema_editor) |
