By default Admin saves an empty string in those TextFields and CharFields defined as null = True.
Whatever the semantic reasons are, this default behavior creates problems in those fields which are both unique = True and null = True because by saving an empty string they do not respect that null != null. For instance suppose you want to create a TextField containing an alphanumeric code which if exists is unique. The default behavior of the Admin forms will save "" in all the empty fields violating the unicity. A work around of would be to override the form used by the admin interface replacing the empty strings with None. On Dec 8, 12:26 am, schinckel <m...@schinckel.net> wrote: > I haven't been able to find any documentation about this, but would be > happy to be pointed in the right direction. > > When you use null=True in a field, and then use that model in the > admin, it will not save NULL to the database, but will instead save an > empty string (or attempt to). > > I think this is broken behaviour: NULL values are semantically > different to empty strings, and in certain cases (I think it was > IPAddressField, but I will have another look later), it would fail to > write to the database. > > Is there a reason that the admin interface saves what should be a NULL > value as an empty string? Do I report this as a bug? > > Matt. -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-develop...@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.