浏览代码

Handle deprecated CheckConstraint.check in 0087 migration

Sage Abdullah 4 月之前
父节点
当前提交
f65282f482
共有 1 个文件被更改,包括 16 次插入8 次删除
  1. 16 8
      wagtail/migrations/0087_alter_grouppagepermission_unique_together_and_more.py

+ 16 - 8
wagtail/migrations/0087_alter_grouppagepermission_unique_together_and_more.py

@@ -1,8 +1,23 @@
 # Generated by Django 4.2.1 on 2023-06-21 11:44
 
+from django import VERSION as DJANGO_VERSION
 from django.db import migrations, models
 
 
+check_constraint_condition = models.Q(
+    ("permission__isnull", False),
+    ("permission_type__isnull", False),
+    _connector="OR",
+)
+
+check_constraint_kwargs = {"name": "permission_or_permission_type_not_null"}
+
+if DJANGO_VERSION >= (5, 1):
+    check_constraint_kwargs["condition"] = check_constraint_condition
+else:
+    check_constraint_kwargs["check"] = check_constraint_condition
+
+
 class Migration(migrations.Migration):
 
     dependencies = [
@@ -16,14 +31,7 @@ class Migration(migrations.Migration):
         ),
         migrations.AddConstraint(
             model_name="grouppagepermission",
-            constraint=models.CheckConstraint(
-                check=models.Q(
-                    ("permission__isnull", False),
-                    ("permission_type__isnull", False),
-                    _connector="OR",
-                ),
-                name="permission_or_permission_type_not_null",
-            ),
+            constraint=models.CheckConstraint(**check_constraint_kwargs),
         ),
         migrations.AddConstraint(
             model_name="grouppagepermission",