Hello,

Let say I want to enforce a database constraint saying a "book's author age 
is over 18".
As you may guess, books and authors are each described with a Model 
subclass with a foreign key (in this example each book is written by a 
single author) linking both.

class Author(models.Model):
    age = models.SmallIntegerField()


class Book(models.Model):
    author = models.ForeignKey(Author, on_delete=models.PROTECT)

    class Meta:
        constraints = [
           models.CheckConstraint(check=models.Q(<WHATEVER>__gt=18), 
name='age_check'),
        ]


I've tried replacing <WHATEVER> above with author_age or author__age.
In both cases, makemigrations works but migrate fails with:
django.core.exceptions.FieldError: Joined field references are not 
permitted in this query


Can I work around this ?
Any working example ?

Best regards

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5231c14e-aa1b-4ffd-8b8b-e14d9e042c35%40googlegroups.com.

Reply via email to