diff options
| author | DevilsAutumn <bhuvnesh875@gmail.com> | 2022-12-25 21:33:02 +0530 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-12-27 07:11:13 +0100 |
| commit | 68ef274bc505cd44f305c03cbf84cf08826200a8 (patch) | |
| tree | 3423c0de079b291b1fdd883a1ac40810b48fbebe | |
| parent | bbeeb45161da251bb7297b60d6155e7b4efdbc9f (diff) | |
Fixed #34217 -- Fixed migration crash when removing check constraints on MySQL < 8.0.16.
| -rw-r--r-- | django/db/backends/base/schema.py | 2 | ||||
| -rw-r--r-- | tests/migrations/test_operations.py | 11 |
2 files changed, 10 insertions, 3 deletions
diff --git a/django/db/backends/base/schema.py b/django/db/backends/base/schema.py index 6697848191..2451fc515a 100644 --- a/django/db/backends/base/schema.py +++ b/django/db/backends/base/schema.py @@ -1651,6 +1651,8 @@ class BaseDatabaseSchemaEditor: ) def _delete_check_sql(self, model, name): + if not self.connection.features.supports_table_check_constraints: + return None return self._delete_constraint_sql(self.sql_delete_check, model, name) def _delete_constraint_sql(self, template, model, name): diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py index dc0d34eebd..2bcb38feae 100644 --- a/tests/migrations/test_operations.py +++ b/tests/migrations/test_operations.py @@ -3630,7 +3630,6 @@ class OperationTests(OperationTestBase): Book.objects.create(read=70, unread=10) Book.objects.create(read=70, unread=30) - @skipUnlessDBFeature("supports_table_check_constraints") def test_remove_constraint(self): project_state = self.set_up_test_model( "test_removeconstraint", @@ -3673,7 +3672,10 @@ class OperationTests(OperationTestBase): "test_removeconstraint", editor, project_state, new_state ) Pony.objects.create(pink=1, weight=1.0).delete() - with self.assertRaises(IntegrityError), transaction.atomic(): + if connection.features.supports_table_check_constraints: + with self.assertRaises(IntegrityError), transaction.atomic(): + Pony.objects.create(pink=100, weight=1.0) + else: Pony.objects.create(pink=100, weight=1.0) # Remove the other one. lt_operation = migrations.RemoveConstraint( @@ -3698,7 +3700,10 @@ class OperationTests(OperationTestBase): gt_operation.database_backwards( "test_removeconstraint", editor, new_state, project_state ) - with self.assertRaises(IntegrityError), transaction.atomic(): + if connection.features.supports_table_check_constraints: + with self.assertRaises(IntegrityError), transaction.atomic(): + Pony.objects.create(pink=1, weight=1.0) + else: Pony.objects.create(pink=1, weight=1.0) # Test deconstruction definition = gt_operation.deconstruct() |
