Refs #23879 -- Made introspection respect required_db_features.
This commit is contained in:
parent
73ac9e3f04
commit
2fb872e56f
|
@ -54,6 +54,16 @@ class BaseDatabaseIntrospection:
|
|||
"""
|
||||
raise NotImplementedError('subclasses of BaseDatabaseIntrospection may require a get_table_list() method')
|
||||
|
||||
def get_migratable_models(self):
|
||||
from django.apps import apps
|
||||
from django.db import router
|
||||
return (
|
||||
model
|
||||
for app_config in apps.get_app_configs()
|
||||
for model in router.get_migratable_models(app_config, self.connection.alias)
|
||||
if model._meta.can_migrate(self.connection)
|
||||
)
|
||||
|
||||
def django_table_names(self, only_existing=False, include_views=True):
|
||||
"""
|
||||
Return a list of all table names that have associated Django models and
|
||||
|
@ -61,11 +71,8 @@ class BaseDatabaseIntrospection:
|
|||
|
||||
If only_existing is True, include only the tables in the database.
|
||||
"""
|
||||
from django.apps import apps
|
||||
from django.db import router
|
||||
tables = set()
|
||||
for app_config in apps.get_app_configs():
|
||||
for model in router.get_migratable_models(app_config, self.connection.alias):
|
||||
for model in self.get_migratable_models():
|
||||
if not model._meta.managed:
|
||||
continue
|
||||
tables.add(model._meta.db_table)
|
||||
|
@ -88,14 +95,9 @@ class BaseDatabaseIntrospection:
|
|||
Return a set of all models represented by the provided list of table
|
||||
names.
|
||||
"""
|
||||
from django.apps import apps
|
||||
from django.db import router
|
||||
all_models = []
|
||||
for app_config in apps.get_app_configs():
|
||||
all_models.extend(router.get_migratable_models(app_config, self.connection.alias))
|
||||
tables = set(map(self.identifier_converter, tables))
|
||||
return {
|
||||
m for m in all_models
|
||||
m for m in self.get_migratable_models()
|
||||
if self.identifier_converter(m._meta.db_table) in tables
|
||||
}
|
||||
|
||||
|
@ -104,13 +106,9 @@ class BaseDatabaseIntrospection:
|
|||
Return a list of information about all DB sequences for all models in
|
||||
all apps.
|
||||
"""
|
||||
from django.apps import apps
|
||||
from django.db import router
|
||||
|
||||
sequence_list = []
|
||||
with self.connection.cursor() as cursor:
|
||||
for app_config in apps.get_app_configs():
|
||||
for model in router.get_migratable_models(app_config, self.connection.alias):
|
||||
for model in self.get_migratable_models():
|
||||
if not model._meta.managed:
|
||||
continue
|
||||
if model._meta.swapped:
|
||||
|
|
Loading…
Reference in New Issue