diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-12-23 23:28:59 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-12-23 23:30:30 +0100 |
| commit | 0f8041abd5bf0977d28b676445d35a81c6b7b5de (patch) | |
| tree | bdfb35dffd666d18cb614509aa2a5a27c334b705 /django | |
| parent | eb40426259cbfd8c4d25797c878424542cf1a1a7 (diff) | |
[3.0.x] Fixed #31106 -- Fixed migrations crash on PostgreSQL 10+ when adding FK constraints inline and changing data.
This allows adding foreign key constraints inline and changing data in
the same migration on PostgreSQL 10+.
Regression in 738faf9da2a5cd03148a36375db80746c99c9623.
Thanks Janne Rönkkö for the report and Simon Charette for the
implementation idea and review.
Backport of 22ce5d0031bd795ade081394043833e82046016c from master
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/backends/postgresql/schema.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/django/db/backends/postgresql/schema.py b/django/db/backends/postgresql/schema.py index 6a65d12415..62e0bf95fd 100644 --- a/django/db/backends/postgresql/schema.py +++ b/django/db/backends/postgresql/schema.py @@ -19,7 +19,12 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): sql_delete_index = "DROP INDEX IF EXISTS %(name)s" sql_delete_index_concurrently = "DROP INDEX CONCURRENTLY IF EXISTS %(name)s" - sql_create_column_inline_fk = 'REFERENCES %(to_table)s(%(to_column)s)%(deferrable)s' + # Setting the constraint to IMMEDIATE to allow changing data in the same + # transaction. + sql_create_column_inline_fk = ( + 'CONSTRAINT %(name)s REFERENCES %(to_table)s(%(to_column)s)%(deferrable)s' + '; SET CONSTRAINTS %(name)s IMMEDIATE' + ) # Setting the constraint to IMMEDIATE runs any deferred checks to allow # dropping it in the same transaction. sql_delete_fk = "SET CONSTRAINTS %(name)s IMMEDIATE; ALTER TABLE %(table)s DROP CONSTRAINT %(name)s" |
