summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2014-09-05 11:59:10 -0700
committerAndrew Godwin <andrew@aeracode.org>2014-09-05 12:05:25 -0700
commitc5578ba9fa052a814c27fe0069f98ed994751634 (patch)
tree95dee8ad2b3593f58eacf5e4586bb22c1c8bc4bd
parentffa9e60638bc1447cba9ddef4585b70267c435f7 (diff)
[1.7.x] Fixed #22411: Throw a more helpful error if contenttypes doesn't exist.
Conflicts: django/contrib/contenttypes/models.py
-rw-r--r--django/contrib/contenttypes/models.py23
1 files changed, 15 insertions, 8 deletions
diff --git a/django/contrib/contenttypes/models.py b/django/contrib/contenttypes/models.py
index 619e15722a..8287b2d6c6 100644
--- a/django/contrib/contenttypes/models.py
+++ b/django/contrib/contenttypes/models.py
@@ -2,6 +2,7 @@ from __future__ import unicode_literals
from django.apps import apps
from django.db import models
+from django.db.utils import OperationalError, ProgrammingError
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import smart_text, force_text
from django.utils.encoding import python_2_unicode_compatible
@@ -42,14 +43,20 @@ class ContentTypeManager(models.Manager):
try:
ct = self._get_from_cache(opts)
except KeyError:
- # Load or create the ContentType entry. The smart_text() is
- # needed around opts.verbose_name_raw because name_raw might be a
- # django.utils.functional.__proxy__ object.
- ct, created = self.get_or_create(
- app_label=opts.app_label,
- model=opts.model_name,
- defaults={'name': smart_text(opts.verbose_name_raw)},
- )
+ try:
+ ct, created = self.get_or_create(
+ app_label=opts.app_label,
+ model=opts.model_name,
+ defaults={'name': smart_text(opts.verbose_name_raw)},
+ )
+ except (OperationalError, ProgrammingError):
+ # It's possible to migrate a single app before contenttypes,
+ # as it's not a required initial dependency (it's contrib!)
+ # Have a nice error for this.
+ raise RuntimeError(
+ "Error creating new content types. Please make sure contenttypes" +
+ " is migrated before trying to migrate apps individually."
+ )
self._add_to_cache(self.db, ct)
return ct