Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove check_migrations from the runserver command and use the new ch…

…ecks framework to check for unapplied migrations. Don't check for migrations if the DATABASES setting is empty.
  • Loading branch information...
commit 0ac13eccebb3d879f79b31585b1e81f655067179 1 parent b041850
Mark Lavin mlavin authored
1  django/core/checks/__init__.py
View
@@ -8,6 +8,7 @@
# Import these to force registration of checks
import django.core.checks.compatibility.django_1_6_0 # NOQA
+import django.core.checks.migrations # NOQA
import django.core.checks.model_checks # NOQA
__all__ = [
31 django/core/checks/migrations.py
View
@@ -0,0 +1,31 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.conf import settings
+
+from . import Warning, register
+
+
+@register('migrations')
+def check_migrations(app_configs=None, **kwargs):
+ """
+ Checks to see if the set of migrations on disk matches the
+ migrations in the database. Prints a warning if they don't match.
+ """
+ from django.db import connections, DEFAULT_DB_ALIAS
+ from django.db.migrations.executor import MigrationExecutor
+
+ errors = []
+ plan = None
+ if settings.DATABASES:
+ executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
+ plan = executor.migration_plan(executor.loader.graph.leaf_nodes())
+ if plan:
+ errors.append(
+ Warning(
+ "You have unapplied migrations; "
+ "your app may not work properly until they are applied.",
+ hint="Run 'python manage.py migrate' to apply them.",
+ )
+ )
+ return errors
14 django/core/management/commands/runserver.py
View
@@ -10,8 +10,6 @@
from django.core.management.base import BaseCommand, CommandError
from django.core.servers.basehttp import run, get_internal_wsgi_application
-from django.db import connections, DEFAULT_DB_ALIAS
-from django.db.migrations.executor import MigrationExecutor
from django.utils import autoreload
from django.utils import six
@@ -101,7 +99,6 @@ def inner_run(self, *args, **options):
self.stdout.write("Performing system checks...\n\n")
self.validate(display_num_errors=True)
- self.check_migrations()
now = datetime.now().strftime('%B %d, %Y - %X')
if six.PY2:
now = now.decode('utf-8')
@@ -146,16 +143,5 @@ def inner_run(self, *args, **options):
self.stdout.write(shutdown_message)
sys.exit(0)
- def check_migrations(self):
- """
- Checks to see if the set of migrations on disk matches the
- migrations in the database. Prints a warning if they don't match.
- """
- executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
- plan = executor.migration_plan(executor.loader.graph.leaf_nodes())
- if plan:
- self.stdout.write(self.style.NOTICE("\nYou have unapplied migrations; your app may not work properly until they are applied."))
- self.stdout.write(self.style.NOTICE("Run 'python manage.py migrate' to apply them.\n"))
-
# Kept for backward compatibility
BaseRunserverCommand = Command
Please sign in to comment.
Something went wrong with that request. Please try again.