[Answered ]-Django Model Unique Constraint Exception

2๐Ÿ‘

โœ…

A unique_together field is validated on database level (see documentation). It is therefore not possible to make exceptions.

A solution could be to set time = null instead of time = 0.
Your database backend needs to support unique constraint that allows empty values (see this post). This is supported by most major DBMS, but not all.

If you database does not support it youโ€™ll have to write a custom form validation.

Leave a comment