I need to allow NULL in enc_id
, but if values are not null, I need those values to be unique. Here's my model:
class Intake(models.Model):
id = models.AutoField(primary_key=True)
enc_id = models.IntegerField(blank=True, null=True, unique=True)
enc_date = models.DateField(null=True)
enrollment = models.ForeignKey('Enrollment')
Error when trying to add another instance without an enc_id
:
django.db.utils.IntegrityError: ('23000', "[23000] [FreeTDS][SQL Server]Violation of UNIQUE KEY constraint 'UQ__caseload__E136D21F4222D4EF'. Cannot insert duplicate key in object 'dbo.caseload_intake'. The duplicate key value is (<NULL>). (2627) (SQLExecDirectW)")
According to what I've read (including this and a few resolved Django issues), having blank=True, null=True, unique=True
should allow me to have duplicate NULLs, but no go. I've recreated my DB just in case and it still raises the integrity error.
I'm running Django 1.10 and MS SQL Server 10. Any ideas?