mirror of
https://github.com/django/django.git
synced 2024-12-24 18:16:19 +00:00
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
|
||||
that actually exist in the database.
|
||||
"""
|
||||
from django.db import models
|
||||
from django.db import models, router
|
||||
tables = set()
|
||||
for app in models.get_apps():
|
||||
for model in models.get_models(app):
|
||||
if not model._meta.managed:
|
||||
continue
|
||||
if not router.allow_syncdb(self.connection.alias, model):
|
||||
continue
|
||||
tables.add(model._meta.db_table)
|
||||
tables.update([f.m2m_db_table() for f in model._meta.local_many_to_many])
|
||||
if only_existing:
|
||||
@ -513,18 +515,19 @@ class BaseDatabaseIntrospection(object):
|
||||
|
||||
def installed_models(self, tables):
|
||||
"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 = []
|
||||
for app in models.get_apps():
|
||||
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
|
||||
if self.table_name_converter(m._meta.db_table) in map(self.table_name_converter, tables)
|
||||
])
|
||||
|
||||
def sequence_list(self):
|
||||
"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()
|
||||
sequence_list = []
|
||||
@ -533,6 +536,8 @@ class BaseDatabaseIntrospection(object):
|
||||
for model in models.get_models(app):
|
||||
if not model._meta.managed:
|
||||
continue
|
||||
if not router.allow_syncdb(self.connection.alias, model):
|
||||
continue
|
||||
for f in model._meta.local_fields:
|
||||
if isinstance(f, models.AutoField):
|
||||
sequence_list.append({'table': model._meta.db_table, 'column': f.column})
|
||||
|
Loading…
Reference in New Issue
Block a user