mirror of
https://github.com/django/django.git
synced 2025-08-30 15:27:40 +00:00
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.
This commit is contained in:
parent
58d0dd9260
commit
cc22b009e0
9 changed files with 97 additions and 0 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue