Fixed #6820: flush no longer fails under PostgreSQL 8.3. WARNING: In the process I renamed a couple of internal functions in django.core.management.sql, so this is a backwards-incompatible change if you were using those internal functions.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7568 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
08d468db92
commit
3de70a10c0
|
@ -21,7 +21,7 @@ class Command(NoArgsCommand):
|
||||||
def handle_noargs(self, **options):
|
def handle_noargs(self, **options):
|
||||||
from django.db import connection, transaction, models
|
from django.db import connection, transaction, models
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.management.sql import table_list, installed_models, sql_model_create, sql_for_pending_references, many_to_many_sql_for_model, custom_sql_for_model, sql_indexes_for_model, emit_post_sync_signal
|
from django.core.management.sql import table_names, installed_models, sql_model_create, sql_for_pending_references, many_to_many_sql_for_model, custom_sql_for_model, sql_indexes_for_model, emit_post_sync_signal
|
||||||
|
|
||||||
verbosity = int(options.get('verbosity', 1))
|
verbosity = int(options.get('verbosity', 1))
|
||||||
interactive = options.get('interactive')
|
interactive = options.get('interactive')
|
||||||
|
@ -45,7 +45,7 @@ class Command(NoArgsCommand):
|
||||||
table_name_converter = lambda x: x
|
table_name_converter = lambda x: x
|
||||||
# Get a list of all existing database tables, so we know what needs to
|
# Get a list of all existing database tables, so we know what needs to
|
||||||
# be added.
|
# be added.
|
||||||
tables = [table_name_converter(name) for name in table_list()]
|
tables = [table_name_converter(name) for name in table_names()]
|
||||||
|
|
||||||
# Get a list of already installed *models* so that references work right.
|
# Get a list of already installed *models* so that references work right.
|
||||||
seen_models = installed_models(tables)
|
seen_models = installed_models(tables)
|
||||||
|
|
|
@ -7,13 +7,13 @@ try:
|
||||||
except NameError:
|
except NameError:
|
||||||
from sets import Set as set # Python 2.3 fallback
|
from sets import Set as set # Python 2.3 fallback
|
||||||
|
|
||||||
def table_list():
|
def table_names():
|
||||||
"Returns a list of all table names that exist in the database."
|
"Returns a list of all table names that exist in the database."
|
||||||
from django.db import connection, get_introspection_module
|
from django.db import connection, get_introspection_module
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
return get_introspection_module().get_table_list(cursor)
|
return set(get_introspection_module().get_table_list(cursor))
|
||||||
|
|
||||||
def django_table_list(only_existing=False):
|
def django_table_names(only_existing=False):
|
||||||
"""
|
"""
|
||||||
Returns a list of all table names that have associated Django models and
|
Returns a list of all table names that have associated Django models and
|
||||||
are in INSTALLED_APPS.
|
are in INSTALLED_APPS.
|
||||||
|
@ -22,14 +22,13 @@ def django_table_list(only_existing=False):
|
||||||
that actually exist in the database.
|
that actually exist in the database.
|
||||||
"""
|
"""
|
||||||
from django.db import models
|
from django.db import models
|
||||||
tables = []
|
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):
|
||||||
tables.append(model._meta.db_table)
|
tables.add(model._meta.db_table)
|
||||||
tables.extend([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:
|
||||||
existing = table_list()
|
tables = [t for t in tables if t in table_names()]
|
||||||
tables = [t for t in tables if t in existing]
|
|
||||||
return tables
|
return tables
|
||||||
|
|
||||||
def installed_models(table_list):
|
def installed_models(table_list):
|
||||||
|
@ -82,7 +81,7 @@ def sql_create(app, style):
|
||||||
# we can be conservative).
|
# we can be conservative).
|
||||||
app_models = models.get_models(app)
|
app_models = models.get_models(app)
|
||||||
final_output = []
|
final_output = []
|
||||||
known_models = set([model for model in installed_models(table_list()) if model not in app_models])
|
known_models = set([model for model in installed_models(table_names()) if model not in app_models])
|
||||||
pending_references = {}
|
pending_references = {}
|
||||||
|
|
||||||
for model in app_models:
|
for model in app_models:
|
||||||
|
@ -214,9 +213,9 @@ def sql_flush(style, only_django=False):
|
||||||
"""
|
"""
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
if only_django:
|
if only_django:
|
||||||
tables = django_table_list()
|
tables = django_table_names()
|
||||||
else:
|
else:
|
||||||
tables = table_list()
|
tables = table_names()
|
||||||
statements = connection.ops.sql_flush(style, tables, sequence_list())
|
statements = connection.ops.sql_flush(style, tables, sequence_list())
|
||||||
return statements
|
return statements
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue