summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2013-11-27 12:34:31 +0000
committerAndrew Godwin <andrew@aeracode.org>2013-11-27 12:34:31 +0000
commit96dd48c83f429688629b866f8fc64e1a4f3249f3 (patch)
tree039a7d4f87ac65b54a8151f6677664312d825be1
parentdb4527e3c0486c46356e3d625931369e8b3bec19 (diff)
Change initial migration writing to work as docs suggest.
Application template now includes an empty migrations module, and the autodetector will only make initial migrations for apps with empty modules.
-rw-r--r--django/conf/app_template/migrations/__init__.py0
-rw-r--r--django/db/migrations/autodetector.py22
2 files changed, 15 insertions, 7 deletions
diff --git a/django/conf/app_template/migrations/__init__.py b/django/conf/app_template/migrations/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/django/conf/app_template/migrations/__init__.py
diff --git a/django/db/migrations/autodetector.py b/django/db/migrations/autodetector.py
index 702221028f..656ce3e939 100644
--- a/django/db/migrations/autodetector.py
+++ b/django/db/migrations/autodetector.py
@@ -1,6 +1,7 @@
import re
+import os
import sys
-from django.utils import datetime_safe
+from django.utils import datetime_safe, importlib
from django.utils.six.moves import input
from django.db.migrations import operations
from django.db.migrations.migration import Migration
@@ -410,15 +411,22 @@ class InteractiveMigrationQuestioner(MigrationQuestioner):
def ask_initial(self, app_label):
"Should we create an initial migration for the app?"
- # Don't ask for django.contrib apps
- app = cache.get_app(app_label)
- if app.__name__.startswith("django.contrib"):
- return False
# If it was specified on the command line, definitely true
if app_label in self.specified_apps:
return True
- # Now ask
- return self._boolean_input("Do you want to enable migrations for app '%s'? [y/N]" % app_label, False)
+ # Otherwise, we look to see if it has a migrations module
+ # without any Python files in it, apart from __init__.py.
+ # Apps from the new app template will have these; the python
+ # file check will ensure we skip South ones.
+ models_module = cache.get_app(app_label)
+ migrations_import_path = "%s.migrations" % models_module.__package__
+ try:
+ migrations_module = importlib.import_module(migrations_import_path)
+ except ImportError:
+ return False
+ else:
+ filenames = os.listdir(os.path.dirname(migrations_module.__file__))
+ return not any(x.endswith(".py") for x in filenames if x != "__init__.py")
def ask_not_null_addition(self, field_name, model_name):
"Adding a NOT NULL field to a model"