summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2016-09-01 16:19:29 -0400
committerGitHub <noreply@github.com>2016-09-01 16:19:29 -0400
commit098c07a03286b5ed133102733e67a83061647ea0 (patch)
tree508e99a5253adc4bf392f8a7aea098eba46c7e97 /django
parent32c02f2a0eaf66e4744f9904eb2a743b87300257 (diff)
downloaddjango-098c07a03286b5ed133102733e67a83061647ea0.tar.gz
Fixed #27142, #27110 -- Made makemigrations consistency checks respect database routers.
Partially reverted refs #27054 except for one of the tests as this solution supersedes that one. Thanks Shai Berger for the review.
Diffstat (limited to 'django')
-rw-r--r--django/core/management/commands/makemigrations.py14
-rw-r--r--django/db/migrations/loader.py8
2 files changed, 11 insertions, 11 deletions
diff --git a/django/core/management/commands/makemigrations.py b/django/core/management/commands/makemigrations.py
index f9f50cc2ad..2fb2d713ca 100644
--- a/django/core/management/commands/makemigrations.py
+++ b/django/core/management/commands/makemigrations.py
@@ -4,8 +4,9 @@ import warnings
from itertools import takewhile
from django.apps import apps
+from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
-from django.db import connections
+from django.db import DEFAULT_DB_ALIAS, connections, router
from django.db.migrations import Migration
from django.db.migrations.autodetector import MigrationAutodetector
from django.db.migrations.loader import MigrationLoader
@@ -94,9 +95,14 @@ class Command(BaseCommand):
loader = MigrationLoader(None, ignore_no_migrations=True)
# Raise an error if any migrations are applied before their dependencies.
- for db in connections:
- connection = connections[db]
- if connection.settings_dict['ENGINE'] != 'django.db.backends.dummy':
+ consistency_check_labels = set(config.label for config in apps.get_app_configs())
+ # Non-default databases are only checked if database routers used.
+ aliases_to_check = connections if settings.DATABASE_ROUTERS else [DEFAULT_DB_ALIAS]
+ for alias in sorted(aliases_to_check):
+ connection = connections[alias]
+ if (connection.settings_dict['ENGINE'] != 'django.db.backends.dummy' and
+ # At least one app must be migrated to the database.
+ any(router.allow_migrate(connection.alias, label) for label in consistency_check_labels)):
loader.check_consistent_history(connection)
# Before anything else, see if there's conflicting apps and drop out
diff --git a/django/db/migrations/loader.py b/django/db/migrations/loader.py
index c78aaed573..ce6fd9e3c0 100644
--- a/django/db/migrations/loader.py
+++ b/django/db/migrations/loader.py
@@ -6,7 +6,6 @@ from importlib import import_module
from django.apps import apps
from django.conf import settings
-from django.db.migrations.exceptions import MigrationSchemaMissing
from django.db.migrations.graph import MigrationGraph
from django.db.migrations.recorder import MigrationRecorder
from django.utils import six
@@ -280,12 +279,7 @@ class MigrationLoader(object):
unapplied dependencies.
"""
recorder = MigrationRecorder(connection)
- try:
- applied = recorder.applied_migrations()
- except MigrationSchemaMissing:
- # Skip check if the django_migrations table is missing and can't be
- # created.
- return
+ applied = recorder.applied_migrations()
for migration in applied:
# If the migration is unknown, skip it.
if migration not in self.graph.nodes: