summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
Diffstat (limited to 'django')
-rw-r--r--django/core/management/commands/migrate.py8
-rw-r--r--django/db/migrations/executor.py17
2 files changed, 16 insertions, 9 deletions
diff --git a/django/core/management/commands/migrate.py b/django/core/management/commands/migrate.py
index d1aff756f0..5dc7dc00f7 100644
--- a/django/core/management/commands/migrate.py
+++ b/django/core/management/commands/migrate.py
@@ -40,6 +40,10 @@ class Command(BaseCommand):
'Defaults to the "default" database.')
parser.add_argument('--fake', action='store_true', dest='fake', default=False,
help='Mark migrations as run without actually running them')
+ parser.add_argument('--fake-initial', action='store_true', dest='fake_initial', default=False,
+ help='Detect if tables already exist and fake-apply initial migrations if so. Make sure '
+ 'that the current database schema matches your initial migration before using this '
+ 'flag. Django will only check for an existing table name.')
parser.add_argument('--list', '-l', action='store_true', dest='list', default=False,
help='Show a list of all known migrations and which are applied')
@@ -186,7 +190,9 @@ class Command(BaseCommand):
"apply them."
))
else:
- executor.migrate(targets, plan, fake=options.get("fake", False))
+ fake = options.get("fake")
+ fake_initial = options.get("fake_initial")
+ executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
# Send the post_migrate signal, so individual apps can do whatever they need
# to do at this point.
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)