mirror of https://github.com/django/django.git
Fixed #30111 -- Fixed AppRegistryNotReady error with django.contrib.postgres in INSTALLED_APPS.
Regression in e192223ed9
.
This commit is contained in:
parent
d02b2aa11e
commit
2804b8d215
|
@ -1,6 +1,7 @@
|
||||||
from django.apps.registry import Apps
|
from django.apps.registry import Apps
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.utils import DatabaseError
|
from django.db.utils import DatabaseError
|
||||||
|
from django.utils.decorators import classproperty
|
||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
|
|
||||||
from .exceptions import MigrationSchemaMissing
|
from .exceptions import MigrationSchemaMissing
|
||||||
|
@ -18,7 +19,15 @@ class MigrationRecorder:
|
||||||
If a migration is unapplied its row is removed from the table. Having
|
If a migration is unapplied its row is removed from the table. Having
|
||||||
a row in the table always means a migration is applied.
|
a row in the table always means a migration is applied.
|
||||||
"""
|
"""
|
||||||
|
_migration_class = None
|
||||||
|
|
||||||
|
@classproperty
|
||||||
|
def Migration(cls):
|
||||||
|
"""
|
||||||
|
Lazy load to avoid AppRegistryNotReady if installed apps import
|
||||||
|
MigrationRecorder.
|
||||||
|
"""
|
||||||
|
if cls._migration_class is None:
|
||||||
class Migration(models.Model):
|
class Migration(models.Model):
|
||||||
app = models.CharField(max_length=255)
|
app = models.CharField(max_length=255)
|
||||||
name = models.CharField(max_length=255)
|
name = models.CharField(max_length=255)
|
||||||
|
@ -26,11 +35,14 @@ class MigrationRecorder:
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
apps = Apps()
|
apps = Apps()
|
||||||
app_label = "migrations"
|
app_label = 'migrations'
|
||||||
db_table = "django_migrations"
|
db_table = 'django_migrations'
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Migration %s for %s" % (self.name, self.app)
|
return 'Migration %s for %s' % (self.name, self.app)
|
||||||
|
|
||||||
|
cls._migration_class = Migration
|
||||||
|
return cls._migration_class
|
||||||
|
|
||||||
def __init__(self, connection):
|
def __init__(self, connection):
|
||||||
self.connection = connection
|
self.connection = connection
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
SECRET_KEY = 'abcdefg'
|
||||||
|
|
||||||
|
INSTALLED_APPS = [
|
||||||
|
'django.contrib.postgres',
|
||||||
|
]
|
|
@ -0,0 +1,17 @@
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from tests.postgres_tests import PostgreSQLSimpleTestCase
|
||||||
|
|
||||||
|
|
||||||
|
class PostgresIntegrationTests(PostgreSQLSimpleTestCase):
|
||||||
|
def test_check(self):
|
||||||
|
os.chdir(os.path.dirname(__file__))
|
||||||
|
result = subprocess.run(
|
||||||
|
[sys.executable, '-m', 'django', 'check', '--settings', 'integration_settings'],
|
||||||
|
stdout=subprocess.DEVNULL,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
)
|
||||||
|
stderr = '\n'.join([e.decode() for e in result.stderr.splitlines()])
|
||||||
|
self.assertEqual(result.returncode, 0, msg=stderr)
|
Loading…
Reference in New Issue