#9781: Admin refuses multiple NULL values for fields marked unique ---------------------------------------------------+------------------------ Reporter: Daniel Pope <[EMAIL PROTECTED]> | Owner: nobody Status: new | Milestone: Component: django.contrib.admin | Version: 1.0 Keywords: null, unique | Stage: Unreviewed Has_patch: 0 | ---------------------------------------------------+------------------------ In all of Django's supported DMBSes, the UNIQUE constraint does not apply to NULL values. This allows the database to represent data of the form "This must be unique where it is set". The Django admin site does not reflect this constraint properly: it treats NULL values as duplicates for the purposes of validation, showing an unwanted error stating that it must be unique.
This behaviour is not universal in DBMSes. Documentation of the capabilities of NULLs in various DBMSes is here: http://www.sqlite.org/nulls.html (This behaviour is "nulls are distinct in a UNIQUE column: Yes"). However, as that page states, there are good reasons why this is done, and the convention has been adopted by all except MSSQL and Informix (and some databases constrain the column specification more strictly so that the issue doesn't arise). There are several use cases where this provides extremely useful functionality, for example: {{{ show_on_page = models.IntegerField(choices=[(1, 'Home page'), (2, 'Contact Page')], blank=True, null=True, unique=True) }}} should allow one instance of the model for the home page, one for the contact page, and any number of other instances where show_on_page is NULL. The admin gives no way of entering a NULL value for a string field but this should work for !IntegerFields etc. -- Ticket URL: <http://code.djangoproject.com/ticket/9781> 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 [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-updates?hl=en -~----------~----~----~----~------~----~------~--~---
