[4.1.x] Fixed #33982 -- Fixed migrations crash when adding model with ExclusionConstraint.
Regression in0e656c02fe
. Backport of19e838daa8
from main
This commit is contained in:
parent
4987ce3350
commit
7ba9a44831
|
@ -269,7 +269,9 @@ class BaseDatabaseSchemaEditor:
|
||||||
sql = self.sql_create_table % {
|
sql = self.sql_create_table % {
|
||||||
"table": self.quote_name(model._meta.db_table),
|
"table": self.quote_name(model._meta.db_table),
|
||||||
"definition": ", ".join(
|
"definition": ", ".join(
|
||||||
constraint for constraint in (*column_sqls, *constraints) if constraint
|
str(constraint)
|
||||||
|
for constraint in (*column_sqls, *constraints)
|
||||||
|
if constraint
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
if model._meta.db_tablespace:
|
if model._meta.db_tablespace:
|
||||||
|
|
|
@ -9,4 +9,5 @@ Django 4.1.2 fixes several bugs in 4.1.1.
|
||||||
Bugfixes
|
Bugfixes
|
||||||
========
|
========
|
||||||
|
|
||||||
* ...
|
* Fixed a regression in Django 4.1 that caused a migration crash on PostgreSQL
|
||||||
|
when adding a model with ``ExclusionConstraint`` (:ticket:`33982`).
|
||||||
|
|
|
@ -10,12 +10,14 @@ from django.db.models import (
|
||||||
F,
|
F,
|
||||||
Func,
|
Func,
|
||||||
IntegerField,
|
IntegerField,
|
||||||
|
Model,
|
||||||
Q,
|
Q,
|
||||||
UniqueConstraint,
|
UniqueConstraint,
|
||||||
)
|
)
|
||||||
from django.db.models.fields.json import KeyTextTransform
|
from django.db.models.fields.json import KeyTextTransform
|
||||||
from django.db.models.functions import Cast, Left, Lower
|
from django.db.models.functions import Cast, Left, Lower
|
||||||
from django.test import ignore_warnings, modify_settings, skipUnlessDBFeature
|
from django.test import ignore_warnings, modify_settings, skipUnlessDBFeature
|
||||||
|
from django.test.utils import isolate_apps
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.deprecation import RemovedInDjango50Warning
|
from django.utils.deprecation import RemovedInDjango50Warning
|
||||||
|
|
||||||
|
@ -1166,6 +1168,29 @@ class ExclusionConstraintTests(PostgreSQLTestCase):
|
||||||
editor.add_constraint(Room, constraint)
|
editor.add_constraint(Room, constraint)
|
||||||
self.assertIn(constraint_name, self.get_constraints(Room._meta.db_table))
|
self.assertIn(constraint_name, self.get_constraints(Room._meta.db_table))
|
||||||
|
|
||||||
|
@isolate_apps("postgres_tests")
|
||||||
|
def test_table_create(self):
|
||||||
|
constraint_name = "exclusion_equal_number_tc"
|
||||||
|
|
||||||
|
class ModelWithExclusionConstraint(Model):
|
||||||
|
number = IntegerField()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
app_label = "postgres_tests"
|
||||||
|
constraints = [
|
||||||
|
ExclusionConstraint(
|
||||||
|
name=constraint_name,
|
||||||
|
expressions=[("number", RangeOperators.EQUAL)],
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
with connection.schema_editor() as editor:
|
||||||
|
editor.create_model(ModelWithExclusionConstraint)
|
||||||
|
self.assertIn(
|
||||||
|
constraint_name,
|
||||||
|
self.get_constraints(ModelWithExclusionConstraint._meta.db_table),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@modify_settings(INSTALLED_APPS={"append": "django.contrib.postgres"})
|
@modify_settings(INSTALLED_APPS={"append": "django.contrib.postgres"})
|
||||||
class ExclusionConstraintOpclassesDepracationTests(PostgreSQLTestCase):
|
class ExclusionConstraintOpclassesDepracationTests(PostgreSQLTestCase):
|
||||||
|
|
Loading…
Reference in New Issue