mirror of
https://github.com/django/django.git
synced 2025-07-04 09:49:12 +00:00
[multi-db] Fixed bug in handling of inter-app pending statements on syncdb.
git-svn-id: http://code.djangoproject.com/svn/django/branches/multiple-db-support@4125 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
025be905d9
commit
91d6569b47
@ -292,13 +292,20 @@ def syncdb(verbosity=2, interactive=True):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
# Install each app
|
# Install each app
|
||||||
|
pending = None
|
||||||
for app in models.get_apps():
|
for app in models.get_apps():
|
||||||
# Install each application (models already installed will be skipped)
|
# Install each application (models already installed will be skipped)
|
||||||
created = _install(app, commit=False, initial_data=False)
|
created, pending = _install(app, commit=False, initial_data=False,
|
||||||
|
pending_allowed=True, pending=pending)
|
||||||
if verbosity >= 2:
|
if verbosity >= 2:
|
||||||
for model in created:
|
for model in created:
|
||||||
print "Created table %s" % model._meta.db_table
|
print "Created table %s" % model._meta.db_table
|
||||||
created_models.extend(created)
|
created_models.extend(created)
|
||||||
|
if pending:
|
||||||
|
transaction.rollback_unless_managed()
|
||||||
|
raise Exception("All apps were installed, but there were still "
|
||||||
|
"pending references to: " + ",".join(pending.keys()) +
|
||||||
|
". Transaction rolled back.")
|
||||||
transaction.commit_unless_managed()
|
transaction.commit_unless_managed()
|
||||||
|
|
||||||
# Send the post_syncdb signal, so individual apps can do whatever they need
|
# Send the post_syncdb signal, so individual apps can do whatever they need
|
||||||
@ -383,7 +390,8 @@ def install(app):
|
|||||||
# doesn't complain about unprintable output.
|
# doesn't complain about unprintable output.
|
||||||
_install(app)
|
_install(app)
|
||||||
|
|
||||||
def _install(app, commit=True, initial_data=True):
|
def _install(app, commit=True, initial_data=True, pending_allowed=False,
|
||||||
|
pending=None):
|
||||||
from django.db import connection, models, transaction
|
from django.db import connection, models, transaction
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@ -396,7 +404,8 @@ def _install(app, commit=True, initial_data=True):
|
|||||||
|
|
||||||
created_models = []
|
created_models = []
|
||||||
try:
|
try:
|
||||||
pending = {}
|
if pending is None:
|
||||||
|
pending = {}
|
||||||
for model in models.get_models(app, creation_order=True):
|
for model in models.get_models(app, creation_order=True):
|
||||||
manager = model._default_manager
|
manager = model._default_manager
|
||||||
tables = manager.get_table_list()
|
tables = manager.get_table_list()
|
||||||
@ -417,7 +426,7 @@ def _install(app, commit=True, initial_data=True):
|
|||||||
for statement in manager.get_pending(rel_class, f):
|
for statement in manager.get_pending(rel_class, f):
|
||||||
statement.execute()
|
statement.execute()
|
||||||
pending.pop(model)
|
pending.pop(model)
|
||||||
else:
|
elif not pending_allowed:
|
||||||
raise Exception("%s is not installed, but it has pending "
|
raise Exception("%s is not installed, but it has pending "
|
||||||
"references" % model)
|
"references" % model)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
@ -433,7 +442,7 @@ The full error: """ % (app_name, app_name)) + style.ERROR_OUTPUT(str(e)) + '\n')
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if commit:
|
if commit:
|
||||||
transaction.commit_unless_managed()
|
transaction.commit_unless_managed()
|
||||||
return created_models
|
return created_models, pending
|
||||||
install.help_doc = "Executes ``sqlall`` for the given app(s) in the current database."
|
install.help_doc = "Executes ``sqlall`` for the given app(s) in the current database."
|
||||||
install.args = APP_ARGS
|
install.args = APP_ARGS
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user