summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2016-08-01 07:57:12 -0400
committerTim Graham <timograham@gmail.com>2016-08-01 07:57:25 -0400
commitddcf7dbae7f6e5fd3c3398aba13bf55b95c80a62 (patch)
tree09b28ba133c58f4776a99dda083d136cebcbe240
parent39387efbba11ea964d3aab69bf26899fe874f5f6 (diff)
[1.10.x] Fixed #26930 -- Prevented makemigrations from accessing an empty database.
Thanks Liz Lemon for the report and investigation and Claude Paroz for the test. Backport of aad46c3e370e105f9117a337924090d05f1b001d from master
-rw-r--r--django/core/management/commands/makemigrations.py4
-rw-r--r--tests/migrations/test_commands.py17
2 files changed, 19 insertions, 2 deletions
diff --git a/django/core/management/commands/makemigrations.py b/django/core/management/commands/makemigrations.py
index b8c05486fc..f9f50cc2ad 100644
--- a/django/core/management/commands/makemigrations.py
+++ b/django/core/management/commands/makemigrations.py
@@ -95,7 +95,9 @@ class Command(BaseCommand):
# Raise an error if any migrations are applied before their dependencies.
for db in connections:
- loader.check_consistent_history(connections[db])
+ connection = connections[db]
+ if connection.settings_dict['ENGINE'] != 'django.db.backends.dummy':
+ loader.check_consistent_history(connection)
# Before anything else, see if there's conflicting apps and drop out
# hard if there are any and they don't want to merge
diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py
index c9efa09667..09abd21103 100644
--- a/tests/migrations/test_commands.py
+++ b/tests/migrations/test_commands.py
@@ -9,7 +9,9 @@ import sys
from django.apps import apps
from django.core.management import CommandError, call_command
-from django.db import DatabaseError, connection, connections, models
+from django.db import (
+ ConnectionHandler, DatabaseError, connection, connections, models,
+)
from django.db.migrations.exceptions import InconsistentMigrationHistory
from django.db.migrations.recorder import MigrationRecorder
from django.test import ignore_warnings, mock, override_settings
@@ -580,6 +582,19 @@ class MakeMigrationsTests(MigrationTestBase):
call_command('makemigrations', 'migrations', '--empty', '-n', 'a', '-v', '0')
self.assertTrue(os.path.exists(os.path.join(migration_dir, '0002_a.py')))
+ def test_makemigrations_empty_connections(self):
+ empty_connections = ConnectionHandler({'default': {}})
+ with mock.patch('django.core.management.commands.makemigrations.connections', new=empty_connections):
+ # with no apps
+ out = six.StringIO()
+ call_command('makemigrations', stdout=out)
+ self.assertIn('No changes detected', out.getvalue())
+ # with an app
+ with self.temporary_migration_module() as migration_dir:
+ call_command('makemigrations', 'migrations', verbosity=0)
+ init_file = os.path.join(migration_dir, '__init__.py')
+ self.assertTrue(os.path.exists(init_file))
+
def test_failing_migration(self):
# If a migration fails to serialize, it shouldn't generate an empty file. #21280
apps.register_model('migrations', UnserializableModel)