Fixed #12976 -- Fixed the sequence reset commands issued by sqlflush in a multidb setup. To achieve this, database introspection was modified to utilize routing information to determine if a model should be available. Thanks to pczapla for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12753 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
ca81ad4f9d
commit
29cb5124a6
|
@ -499,12 +499,14 @@ class BaseDatabaseIntrospection(object):
|
||||||
If only_existing is True, the resulting list will only include the tables
|
If only_existing is True, the resulting list will only include the tables
|
||||||
that actually exist in the database.
|
that actually exist in the database.
|
||||||
"""
|
"""
|
||||||
from django.db import models
|
from django.db import models, router
|
||||||
tables = set()
|
tables = set()
|
||||||
for app in models.get_apps():
|
for app in models.get_apps():
|
||||||
for model in models.get_models(app):
|
for model in models.get_models(app):
|
||||||
if not model._meta.managed:
|
if not model._meta.managed:
|
||||||
continue
|
continue
|
||||||
|
if not router.allow_syncdb(self.connection.alias, model):
|
||||||
|
continue
|
||||||
tables.add(model._meta.db_table)
|
tables.add(model._meta.db_table)
|
||||||
tables.update([f.m2m_db_table() for f in model._meta.local_many_to_many])
|
tables.update([f.m2m_db_table() for f in model._meta.local_many_to_many])
|
||||||
if only_existing:
|
if only_existing:
|
||||||
|
@ -513,18 +515,19 @@ class BaseDatabaseIntrospection(object):
|
||||||
|
|
||||||
def installed_models(self, tables):
|
def installed_models(self, tables):
|
||||||
"Returns a set of all models represented by the provided list of table names."
|
"Returns a set of all models represented by the provided list of table names."
|
||||||
from django.db import models
|
from django.db import models, router
|
||||||
all_models = []
|
all_models = []
|
||||||
for app in models.get_apps():
|
for app in models.get_apps():
|
||||||
for model in models.get_models(app):
|
for model in models.get_models(app):
|
||||||
all_models.append(model)
|
if router.allow_syncdb(self.connection.alias, model):
|
||||||
|
all_models.append(model)
|
||||||
return set([m for m in all_models
|
return set([m for m in all_models
|
||||||
if self.table_name_converter(m._meta.db_table) in map(self.table_name_converter, tables)
|
if self.table_name_converter(m._meta.db_table) in map(self.table_name_converter, tables)
|
||||||
])
|
])
|
||||||
|
|
||||||
def sequence_list(self):
|
def sequence_list(self):
|
||||||
"Returns a list of information about all DB sequences for all models in all apps."
|
"Returns a list of information about all DB sequences for all models in all apps."
|
||||||
from django.db import models
|
from django.db import models, router
|
||||||
|
|
||||||
apps = models.get_apps()
|
apps = models.get_apps()
|
||||||
sequence_list = []
|
sequence_list = []
|
||||||
|
@ -533,6 +536,8 @@ class BaseDatabaseIntrospection(object):
|
||||||
for model in models.get_models(app):
|
for model in models.get_models(app):
|
||||||
if not model._meta.managed:
|
if not model._meta.managed:
|
||||||
continue
|
continue
|
||||||
|
if not router.allow_syncdb(self.connection.alias, model):
|
||||||
|
continue
|
||||||
for f in model._meta.local_fields:
|
for f in model._meta.local_fields:
|
||||||
if isinstance(f, models.AutoField):
|
if isinstance(f, models.AutoField):
|
||||||
sequence_list.append({'table': model._meta.db_table, 'column': f.column})
|
sequence_list.append({'table': model._meta.db_table, 'column': f.column})
|
||||||
|
|
Loading…
Reference in New Issue