diff --git a/tenant_schemas/apps.py b/tenant_schemas/apps.py index 6b16b621..cf4b7bc6 100644 --- a/tenant_schemas/apps.py +++ b/tenant_schemas/apps.py @@ -2,6 +2,7 @@ from django.conf import settings from django.core.checks import Critical, Error, Warning, register from django.core.files.storage import default_storage +from django.db import connection from tenant_schemas.storage import TenantStorageMixin from tenant_schemas.utils import get_public_schema_name, get_tenant_model @@ -67,12 +68,15 @@ def best_practice(app_configs, **kwargs): % get_public_schema_name())) # make sure no tenant schema is in settings.PG_EXTRA_SEARCH_PATHS - invalid_schemas = set(settings.PG_EXTRA_SEARCH_PATHS).intersection( - get_tenant_model().objects.all().values_list('schema_name', flat=True)) - if invalid_schemas: - errors.append(Critical( - "Do not include tenant schemas (%s) on PG_EXTRA_SEARCH_PATHS." - % ", ".join(sorted(invalid_schemas)))) + tenant_model = get_tenant_model() + # but avoid check during initial migration(s) when the table for tenant model is not created yet + if tenant_model._meta.db_table in connection.introspection.table_names(): + invalid_schemas = set(settings.PG_EXTRA_SEARCH_PATHS).intersection( + tenant_model.objects.all().values_list('schema_name', flat=True)) + if invalid_schemas: + errors.append(Critical( + "Do not include tenant schemas (%s) on PG_EXTRA_SEARCH_PATHS." + % ", ".join(sorted(invalid_schemas)))) if not settings.SHARED_APPS: errors.append(