summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorNasir Hussain <nasirhjafri@gmail.com>2019-01-23 03:49:30 +0500
committerTim Graham <timograham@gmail.com>2019-01-22 17:50:00 -0500
commit6ce7887f1387855df2cda180da08277febedd02e (patch)
treecc20f6e2d9f2983fc368547d480f8d5e38ce3d82 /django
parent51247bc55f862c01bde60da6c07d9610bfe94835 (diff)
[2.2.x] Fixed #30111 -- Fixed AppRegistryNotReady error with django.contrib.postgres in INSTALLED_APPS.
Regression in e192223ed996ed30fe83787efdfa7f2be6b1a2ee. Backport of 2804b8d2153505ec49b191db2168302dfb92c3af from master.
Diffstat (limited to 'django')
-rw-r--r--django/db/migrations/recorder.py32
1 files changed, 22 insertions, 10 deletions
diff --git a/django/db/migrations/recorder.py b/django/db/migrations/recorder.py
index 3a972fe4c6..ad5435d906 100644
--- a/django/db/migrations/recorder.py
+++ b/django/db/migrations/recorder.py
@@ -1,6 +1,7 @@
from django.apps.registry import Apps
from django.db import models
from django.db.utils import DatabaseError
+from django.utils.decorators import classproperty
from django.utils.timezone import now
from .exceptions import MigrationSchemaMissing
@@ -18,19 +19,30 @@ class MigrationRecorder:
If a migration is unapplied its row is removed from the table. Having
a row in the table always means a migration is applied.
"""
+ _migration_class = None
- class Migration(models.Model):
- app = models.CharField(max_length=255)
- name = models.CharField(max_length=255)
- applied = models.DateTimeField(default=now)
+ @classproperty
+ def Migration(cls):
+ """
+ Lazy load to avoid AppRegistryNotReady if installed apps import
+ MigrationRecorder.
+ """
+ if cls._migration_class is None:
+ class Migration(models.Model):
+ app = models.CharField(max_length=255)
+ name = models.CharField(max_length=255)
+ applied = models.DateTimeField(default=now)
- class Meta:
- apps = Apps()
- app_label = "migrations"
- db_table = "django_migrations"
+ class Meta:
+ apps = Apps()
+ app_label = 'migrations'
+ db_table = 'django_migrations'
- def __str__(self):
- return "Migration %s for %s" % (self.name, self.app)
+ def __str__(self):
+ return 'Migration %s for %s' % (self.name, self.app)
+
+ cls._migration_class = Migration
+ return cls._migration_class
def __init__(self, connection):
self.connection = connection