'MySQL 8.0.27 not accepting django check constraints
I have seen a 2 years old similar question to this but the question did not specify the MySQL version and there is no answers to the question.
I'm use the django(2.2.28) constraint API to create a model that has 2 foreign keys but both of them cannot exist together and both of them cannot be null at the same time. The constraints look something like this:
CheckConstraint(check=Q(type='campaign', campaign__isnull=False), name='check_campaign_data'),
CheckConstraint(check=Q(type='trigger', trigger__isnull=False), name='check_trigger_data'),
The type indicates which foreign key the model will be using.
However, the following warning appears on my console:
(models.W027) MySQL does not support check constraints.
HINT: A constraint won't be created. Silence this warning if you don't care about it.
I have seen that this is now supported for MySQL 8.0.16 or higher.
I logged into the MySQL database and ran the command
mysql> SELECT VERSION();
+-----------+
| VERSION() |
+-----------+
| 8.0.27 |
+-----------+
Why is this not working if this version of MySQL is supposed to support this feature?
Solution 1:[1]
I have done what Bill karwin suggested and saw that the Check Constraint is in fact created and works as expected even with the warning. To ignore the warning I just added the following to my settings.py:
SILENCED_SYSTEM_CHECKS = ["models.W027"]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Romero Cartaxo |
