Fixed #22576: Ensure makemigrations doesn't touch the database.

This commit is contained in:
Andrew Godwin 2014-05-06 22:41:59 -07:00
parent 6944418277
commit f9d7e18dc5
2 changed files with 8 additions and 6 deletions

View File

@ -50,10 +50,9 @@ class Command(BaseCommand):
self.stderr.write("App '%s' could not be found. Is it in INSTALLED_APPS?" % app_label) self.stderr.write("App '%s' could not be found. Is it in INSTALLED_APPS?" % app_label)
sys.exit(2) sys.exit(2)
# Load the current graph state. Takes a connection, but it's not used # Load the current graph state. Pass in None for the connection so
# (makemigrations doesn't look at the database state). # the loader doesn't try to resolve replaced migrations from DB.
# Also make sure the graph is built without unmigrated apps shoehorned in. loader = MigrationLoader(None)
loader = MigrationLoader(connections[DEFAULT_DB_ALIAS])
# Before anything else, see if there's conflicting apps and drop out # Before anything else, see if there's conflicting apps and drop out
# hard if there are any and they don't want to merge # hard if there are any and they don't want to merge

View File

@ -143,8 +143,11 @@ class MigrationLoader(object):
# Load disk data # Load disk data
self.load_disk() self.load_disk()
# Load database data # Load database data
recorder = MigrationRecorder(self.connection) if self.connection is None:
self.applied_migrations = recorder.applied_migrations() self.applied_migrations = set()
else:
recorder = MigrationRecorder(self.connection)
self.applied_migrations = recorder.applied_migrations()
# Do a first pass to separate out replacing and non-replacing migrations # Do a first pass to separate out replacing and non-replacing migrations
normal = {} normal = {}
replacing = {} replacing = {}