Loading django/db/migrations/executor.py +5 −3 Original line number Diff line number Diff line Loading @@ -132,11 +132,13 @@ class MigrationExecutor(object): """ project_state = self.loader.project_state((migration.app_label, migration.name), at_end=True) apps = project_state.render() found_create_migration = False for operation in migration.operations: if isinstance(operation, migrations.CreateModel): model = apps.get_model(migration.app_label, operation.name) if model._meta.db_table not in self.connection.introspection.get_table_list(self.connection.cursor()): return False else: return False return True found_create_migration = True # If we get this far and we found at least one CreateModel migration, # the migration is considered implicitly applied. return found_create_migration tests/migrations/test_executor.py +14 −0 Original line number Diff line number Diff line Loading @@ -155,6 +155,12 @@ class ExecutorTests(MigrationTestBase): self.assertTableNotExists("migrations_author") self.assertTableNotExists("migrations_tribble") # Run it normally self.assertEqual( executor.migration_plan([("migrations", "0001_initial")]), [ (executor.loader.graph.nodes["migrations", "0001_initial"], False), ], ) executor.migrate([("migrations", "0001_initial")]) # Are the tables there now? self.assertTableExists("migrations_author") Loading @@ -171,9 +177,17 @@ class ExecutorTests(MigrationTestBase): # Make sure that was faked self.assertEqual(state["faked"], True) # Finally, migrate forwards; this should fake-apply our initial migration executor.loader.build_graph() self.assertEqual( executor.migration_plan([("migrations", "0001_initial")]), [ (executor.loader.graph.nodes["migrations", "0001_initial"], False), ], ) executor.migrate([("migrations", "0001_initial")]) self.assertEqual(state["faked"], True) # And migrate back to clean up the database executor.loader.build_graph() executor.migrate([("migrations", None)]) self.assertTableNotExists("migrations_author") self.assertTableNotExists("migrations_tribble") Loading tests/migrations/test_migrations/0001_initial.py +6 −1 Original line number Diff line number Diff line Loading @@ -25,6 +25,11 @@ class Migration(migrations.Migration): ("id", models.AutoField(primary_key=True)), ("fluffy", models.BooleanField(default=True)), ], ) ), migrations.AlterUniqueTogether( name='author', unique_together=set([('name', 'slug')]), ), ] Loading
django/db/migrations/executor.py +5 −3 Original line number Diff line number Diff line Loading @@ -132,11 +132,13 @@ class MigrationExecutor(object): """ project_state = self.loader.project_state((migration.app_label, migration.name), at_end=True) apps = project_state.render() found_create_migration = False for operation in migration.operations: if isinstance(operation, migrations.CreateModel): model = apps.get_model(migration.app_label, operation.name) if model._meta.db_table not in self.connection.introspection.get_table_list(self.connection.cursor()): return False else: return False return True found_create_migration = True # If we get this far and we found at least one CreateModel migration, # the migration is considered implicitly applied. return found_create_migration
tests/migrations/test_executor.py +14 −0 Original line number Diff line number Diff line Loading @@ -155,6 +155,12 @@ class ExecutorTests(MigrationTestBase): self.assertTableNotExists("migrations_author") self.assertTableNotExists("migrations_tribble") # Run it normally self.assertEqual( executor.migration_plan([("migrations", "0001_initial")]), [ (executor.loader.graph.nodes["migrations", "0001_initial"], False), ], ) executor.migrate([("migrations", "0001_initial")]) # Are the tables there now? self.assertTableExists("migrations_author") Loading @@ -171,9 +177,17 @@ class ExecutorTests(MigrationTestBase): # Make sure that was faked self.assertEqual(state["faked"], True) # Finally, migrate forwards; this should fake-apply our initial migration executor.loader.build_graph() self.assertEqual( executor.migration_plan([("migrations", "0001_initial")]), [ (executor.loader.graph.nodes["migrations", "0001_initial"], False), ], ) executor.migrate([("migrations", "0001_initial")]) self.assertEqual(state["faked"], True) # And migrate back to clean up the database executor.loader.build_graph() executor.migrate([("migrations", None)]) self.assertTableNotExists("migrations_author") self.assertTableNotExists("migrations_tribble") Loading
tests/migrations/test_migrations/0001_initial.py +6 −1 Original line number Diff line number Diff line Loading @@ -25,6 +25,11 @@ class Migration(migrations.Migration): ("id", models.AutoField(primary_key=True)), ("fluffy", models.BooleanField(default=True)), ], ) ), migrations.AlterUniqueTogether( name='author', unique_together=set([('name', 'slug')]), ), ]