summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorMarti Raudsepp <marti@juffo.org>2016-11-05 10:16:23 +0200
committerTim Graham <timograham@gmail.com>2017-06-19 13:04:57 -0400
commitfda55c71a8846364b9dc4f4efac4d7034ef6dd6f (patch)
treef9e97004ef01b4b5e7e5c9d2fd0b0e281c3879ab /django
parent4f1eb64ad0bcebfae4075486855eb6b63355cc5a (diff)
Fixed #27858 -- Prevented read-only management commands from creating the django_migrations table.
MigrationRecorder now assumes that if the django_migrations table doesn't exist, then no migrations are applied. Reverted documentation change from refs #23808.
Diffstat (limited to 'django')
-rw-r--r--django/core/management/base.py6
-rw-r--r--django/db/migrations/executor.py4
-rw-r--r--django/db/migrations/recorder.py14
3 files changed, 15 insertions, 9 deletions
diff --git a/django/core/management/base.py b/django/core/management/base.py
index bfc6811e28..41b6b0fa91 100644
--- a/django/core/management/base.py
+++ b/django/core/management/base.py
@@ -12,7 +12,6 @@ from django.core import checks
from django.core.exceptions import ImproperlyConfigured
from django.core.management.color import color_style, no_style
from django.db import DEFAULT_DB_ALIAS, connections
-from django.db.migrations.exceptions import MigrationSchemaMissing
class CommandError(Exception):
@@ -429,11 +428,6 @@ class BaseCommand:
except ImproperlyConfigured:
# No databases are configured (or the dummy one)
return
- except MigrationSchemaMissing:
- self.stdout.write(self.style.NOTICE(
- "\nNot checking migrations as it is not possible to access/create the django_migrations table."
- ))
- return
plan = executor.migration_plan(executor.loader.graph.leaf_nodes())
if plan:
diff --git a/django/db/migrations/executor.py b/django/db/migrations/executor.py
index ab412fe6d1..ea7bc70db3 100644
--- a/django/db/migrations/executor.py
+++ b/django/db/migrations/executor.py
@@ -86,6 +86,10 @@ class MigrationExecutor:
Django first needs to create all project states before a migration is
(un)applied and in a second step run all the database operations.
"""
+ # The django_migrations table must be present to record applied
+ # migrations.
+ self.recorder.ensure_schema()
+
if plan is None:
plan = self.migration_plan(targets)
# Create the forwards plan Django would follow on an empty database
diff --git a/django/db/migrations/recorder.py b/django/db/migrations/recorder.py
index dcc27d525c..2a3ff8bb99 100644
--- a/django/db/migrations/recorder.py
+++ b/django/db/migrations/recorder.py
@@ -39,11 +39,15 @@ class MigrationRecorder:
def migration_qs(self):
return self.Migration.objects.using(self.connection.alias)
+ def has_table(self):
+ """Return True if the django_migrations table exists."""
+ return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
+
def ensure_schema(self):
"""Ensure the table exists and has the correct schema."""
# If the table's there, that's fine - we've never changed its schema
# in the codebase.
- if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
+ if self.has_table():
return
# Make the table
try:
@@ -54,8 +58,12 @@ class MigrationRecorder:
def applied_migrations(self):
"""Return a set of (app, name) of applied migrations."""
- self.ensure_schema()
- return {tuple(x) for x in self.migration_qs.values_list("app", "name")}
+ if self.has_table():
+ return {tuple(x) for x in self.migration_qs.values_list('app', 'name')}
+ else:
+ # If the django_migrations table doesn't eixst, then no migrations
+ # are applied.
+ return set()
def record_applied(self, app, name):
"""Record that a migration was applied."""