- Django 3 Web Development Cookbook
- Aidas Bendoraitis Jake Kronika
- 80字
- 2025-04-04 13:15:08
Adding database constraints
For better database integrity, it's common to define database constraints, telling some fields to be bound to fields of other database tables, making some fields unique or not null. For advanced database constraints, such as making the fields unique with a condition or setting specific conditions for the values of some fields, Django has special classes: UniqueConstraint and CheckConstraint. In this recipe, you will see a practical example of how to use them.