1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Refs #11964 -- Made constraint support check respect required_db_features.

This will notably silence the warnings issued when running the test
suite on MySQL.
This commit is contained in:
Simon Charette
2019-08-10 02:41:18 -04:00
committed by Mariusz Felisiak
parent 2fb872e56f
commit 8b3e1b6e9e
6 changed files with 67 additions and 26 deletions

View File

@@ -2,12 +2,13 @@ from django.db import models
class Product(models.Model):
name = models.CharField(max_length=255)
color = models.CharField(max_length=32, null=True)
price = models.IntegerField(null=True)
discounted_price = models.IntegerField(null=True)
class Meta:
required_db_features = {
'supports_table_check_constraints',
}
constraints = [
models.CheckConstraint(
check=models.Q(price__gt=models.F('discounted_price')),
@@ -17,6 +18,15 @@ class Product(models.Model):
check=models.Q(price__gt=0),
name='%(app_label)s_%(class)s_price_gt_0',
),
]
class UniqueConstraintProduct(models.Model):
name = models.CharField(max_length=255)
color = models.CharField(max_length=32, null=True)
class Meta:
constraints = [
models.UniqueConstraint(fields=['name', 'color'], name='name_color_uniq'),
models.UniqueConstraint(
fields=['name'],
@@ -31,6 +41,9 @@ class AbstractModel(models.Model):
class Meta:
abstract = True
required_db_features = {
'supports_table_check_constraints',
}
constraints = [
models.CheckConstraint(
check=models.Q(age__gte=18),