#15884: Model validation allows nullable primary key field.
---------------------------+-------------------------------
 Reporter:  JustinTArthur  |          Owner:  JustinTArthur
     Type:  Bug            |         Status:  new
Milestone:                 |      Component:  Uncategorized
  Version:  1.3            |       Severity:  Normal
 Keywords:                 |   Triage Stage:  Unreviewed
Has patch:  0              |  Easy pickings:  0
---------------------------+-------------------------------
 If I have a primary key field that is also nullable, the model validation
 code is currently allowing it:
 {{{
 #!python
 class MyModel(models.Model):
     other_model = OneToOneField(OtherModel, primary_key=True, null=True)
 }}}

 This behavior seems like a defect given two circumstances:
  * No SQL implementation I know of allows a primary key column to be
 `NULL` in the schema.
  * Django's `CASCADE` deletion will `None`/`NULL` out any `null=True`
 foreign keys (see source:/trunk/django/db/models/deletion.py@15927#L19),
   * While a SQL backend might correctly map the `None` to a `0` instead of
 `NULL` in the `UPDATE` statement, after a second deletion against the same
 table, you would have more than one row with primary key of `0`, thus
 violating the uniqueness constraint intrinsic to a primary key field.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/15884>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

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

Reply via email to