>From the looks of it, it seems MSSQL isn't following the standard
regarding null equality in unique indexes. You might be interested in:
http://connect.microsoft.com/SQLServer/feedback/details/299229/change-unique-constraint-to-allow-multiple-null-values

Depending on your server version you might have a possibility to
define a filtered unique contraint. Otherwise, remove the constraint
in the database schema (the django model could still have the
OneToOneField for validation purposes) or alter your business logic in
a way that the referenced Unit models are also deleted.

 - Anssi

On Feb 18, 9:38 pm, Eugeny Klementev <eugeny.klemen...@gmail.com>
wrote:
> I have two models with OneToOne relation
>
> class Unit (models.Model):
>     label = models.CharField(max_length=32)
>     datastream = models.OneToOneField ('Datastream', null=True, blank=True,
> related_name="unit")
>     ...
>
> class Datastream (models.Model):
>     idd = models.AutoField(primary_key=True, auto_created=True, null=True)
>     id = models.CharField(max_length=32)
>     ...
>
> During deletion of datastream these commands executed on DB server:
>
> SQL: UPDATE "feeds_unit" SET "datastream_id" = NULL WHERE "id" IN (?, ?, ?)
> PARAMS: (4, 5, 6)
>
> SQL: DELETE FROM "feeds_unit" WHERE "id" IN (?, ?, ?)
> PARAMS: (6, 5, 4)
>
> I tried sqlite3 as backend - works fine.
> But MSSQL raise error on "UPDATE "feeds_unit" SET "datastream_id" = NULL
> WHERE "id" IN (?, ?, ?)"
> Error:
> IntegrityError: ('23000', "[23000] [Microsoft][ODBC SQL Server Driver][SQL
> Server]Violation of UNIQU
> E KEY constraint 'UQ__feeds_un__EAC1B8893E847883'. Cannot insert duplicate
> key in object 'dbo.feeds_
> unit'. The duplicate key value is (<NULL>). (2627) (SQLExecDirectW);
> [01000] [Microsoft][ODBC SQL Se
> rver Driver][SQL Server]The statement has been terminated. (3621)")
>
> Can anybody help me?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to