diff options
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/migrations/recorder.py | 32 |
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 |
