diff options
| author | Markus Holtermann <info@markusholtermann.eu> | 2015-02-11 10:14:53 +0100 |
|---|---|---|
| committer | Markus Holtermann <info@markusholtermann.eu> | 2015-02-16 19:31:51 +0100 |
| commit | cc22b009e05456e3d9cf3c152fe47fa27772be5e (patch) | |
| tree | 5199cb1200cd05ee6a26b8bcb1c5f5b27423cf13 /tests/migrations/test_executor.py | |
| parent | 58d0dd9260156067263ea7a2da2685c3cd88e18a (diff) | |
Refs #24264 -- Added failing test case for updating a FK when changing a PK
When the primary key column is altered, foreign keys of referencing
models must be aware of a possible data type change as well and thus
need to be re-rendered.
Thanks Tim Graham for the report.
Diffstat (limited to 'tests/migrations/test_executor.py')
| -rw-r--r-- | tests/migrations/test_executor.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/migrations/test_executor.py b/tests/migrations/test_executor.py index b88307ceea..b05eb04514 100644 --- a/tests/migrations/test_executor.py +++ b/tests/migrations/test_executor.py @@ -376,6 +376,41 @@ class ExecutorTests(MigrationTestBase): ] self.assertEqual(call_args_list, expected) + @override_settings( + INSTALLED_APPS=[ + "migrations.migrations_test_apps.alter_fk.author_app", + "migrations.migrations_test_apps.alter_fk.book_app", + ] + ) + def test_alter_id_type_with_fk(self): + try: + executor = MigrationExecutor(connection) + self.assertTableNotExists("author_app_author") + self.assertTableNotExists("book_app_book") + # Apply initial migrations + executor.migrate([ + ("author_app", "0001_initial"), + ("book_app", "0001_initial"), + ]) + self.assertTableExists("author_app_author") + self.assertTableExists("book_app_book") + # Rebuild the graph to reflect the new DB state + executor.loader.build_graph() + + # Apply PK type alteration + executor.migrate([("author_app", "0002_alter_id")]) + + # Rebuild the graph to reflect the new DB state + executor.loader.build_graph() + finally: + # We can't simply unapply the migrations here because there is no + # implicit cast from VARCHAR to INT on the database level. + with connection.schema_editor() as editor: + editor.execute(editor.sql_delete_table % {"table": "book_app_book"}) + editor.execute(editor.sql_delete_table % {"table": "author_app_author"}) + self.assertTableNotExists("author_app_author") + self.assertTableNotExists("book_app_book") + class FakeLoader(object): def __init__(self, graph, applied): |
