diff options
author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2006-08-09 07:16:35 +0000 |
---|---|---|
committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2006-08-09 07:16:35 +0000 |
commit | 5ca28474f9e554170fd96a2b2ddd4fa1305807ce (patch) | |
tree | e31644dabc3b9acca03877b8cf836c94fc170345 | |
parent | d9d44d718b5aa2c8e5e227c9df51cda56c1101be (diff) | |
download | django-5ca28474f9e554170fd96a2b2ddd4fa1305807ce.tar.gz |
Fixed #2260 -- fixed a problem where some foreign key references were being
omitted during a "reset" or "sqlreset". Thanks, marcink@elksoft.pl.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3542 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r-- | django/core/management.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/django/core/management.py b/django/core/management.py index bddac1075a..4cf7bcea3d 100644 --- a/django/core/management.py +++ b/django/core/management.py @@ -94,12 +94,15 @@ def get_sql_create(app): "Edit your settings file and change DATABASE_ENGINE to something like 'postgresql' or 'mysql'.\n")) sys.exit(1) - # Get installed models, so we generate REFERENCES right + # Get installed models, so we generate REFERENCES right. + # We trim models from the current app so that the sqlreset command does not + # generate invalid SQL (leaving models out of known_models is harmless, so + # we can be conservative). + app_models = models.get_models(app) final_output = [] - known_models = set(_get_installed_models(_get_table_list())) + known_models = set([model for model in _get_installed_models(_get_table_list()) if model not in app_models]) pending_references = {} - app_models = models.get_models(app) for model in app_models: output, references = _get_sql_model_create(model, known_models) @@ -118,10 +121,13 @@ def get_sql_create(app): # but don't exist physically not_installed_models = set(pending_references.keys()) if not_installed_models: - final_output.append('-- The following references should be added but depend on non-existant tables:') + alter_sql = [] for model in not_installed_models: - final_output.extend(['-- ' + sql for sql in + alter_sql.extend(['-- ' + sql for sql in _get_sql_for_pending_references(model, pending_references)]) + if alter_sql: + final_output.append('-- The following references should be added but depend on non-existent tables:') + final_output.extend(alter_sql) return final_output get_sql_create.help_doc = "Prints the CREATE TABLE SQL statements for the given app name(s)." |