Changes between Initial Version and Version 1 of Ticket #23379
- Timestamp:
- Aug 28, 2014, 12:28:27 PM (10 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #23379 – Description
initial v1 5 5 1) python manage.py repro # generates correct sql 6 6 7 {{{#!sql 7 8 CREATE TABLE `repro_app_a` ( 8 9 `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, … … 17 18 ALTER TABLE `repro_app_b` ADD CONSTRAINT `a_id_refs_id_4838e71a` FOREIGN KEY (`a_id`) REFERENCES `repro_app_a` (`id`); 18 19 ALTER TABLE `repro_app_a` ADD CONSTRAINT `b_id_refs_id_b49a3179` FOREIGN KEY (`b_id`) REFERENCES `repro_app_b` (`id`); 19 20 }}} 20 21 2) python manage.py migrate 21 22 3) python manage.py repro # generates incorrect sql; the first constraint fails because table repro_app_b hasn't been created yet. 22 23 {{{#!sql 23 24 CREATE TABLE `repro_app_a` ( 24 25 `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, … … 33 34 ; 34 35 ALTER TABLE `repro_app_b` ADD CONSTRAINT `a_id_refs_id_4838e71a` FOREIGN KEY (`a_id`) REFERENCES `repro_app_a` (`id`); 35 36 }}} 36 37 37 38 Fortunately, the (or, "a") fix is an easy one-liner: 38 39 39 diff --git a/django/core/management/sql.py b/django/core/management/sql.py 40 index 323cb54..048b051 100644 40 {{{ 41 #!diff 41 42 --- a/django/core/management/sql.py 42 43 +++ b/django/core/management/sql.py … … 50 51 tables = connection.introspection.table_names() 51 52 known_models = set(model for model in connection.introspection.installed_models(tables) if model not in app_models) 52 53 }}}