Using trunk, I have a model that has a number of fields which are CharFields, that I would like to be optional but if they are filled out, unique.
I express this with: tab = meta.CharField(maxlength=15, unique=True, blank=True) Creating the first object in admin with a blank tab field works just fine. However, if I try to create a second object with a blank tab field, I get an IntegrityError warning me of a duplicate key. Traceback (most recent call last): File "/home/fanfatale/src/django/django/core/handlers/base.py" in get_response 74. response = callback(request, *callback_args, **callback_kwargs) File "/home/fanfatale/src/django/django/contrib/admin/views/decorators.py" in _checklogin 54. return view_func(request, *args, **kwargs) File "/home/fanfatale/src/django/django/contrib/admin/views/main.py" in add_stage 408. new_object = manipulator.save(new_data) File "/home/fanfatale/src/django/django/utils/functional.py" in _curried 3. return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items())) File "/home/fanfatale/usr/lib/python2.3/site-packages/django/core/meta/__init__.py" in manipulator_save 1773. new_object.save() File "/home/fanfatale/src/django/django/utils/functional.py" in _curried 3. return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items())) File "/home/fanfatale/usr/lib/python2.3/site-packages/django/core/meta/__init__.py" in method_save 1026. ','.join(placeholders)), db_values) File "/home/fanfatale/src/django/django/core/db/base.py" in execute 10. result = self.cursor.execute(sql, params) File "/home/fanfatale/src/django/django/core/db/backends/mysql.py" in execute 32. return self.cursor.execute(sql, params) File "/usr/lib/python2.3/site-packages/MySQLdb/cursors.py" in execute 137. self.errorhandler(self, exc, value) File "/usr/lib/python2.3/site-packages/MySQLdb/connections.py" in defaulterrorhandler 33. raise errorclass, errorvalue IntegrityError at /admin/inventory/textpages/add/ (1062, "Duplicate entry '' for key 3") As long as I fill out the tab field with a unique string, I can continue to add objects with no problems. So it seem like what is happening is that because of the unique requirement, there can be only one record with an empty string. My first thought was to ignore the docs and use null=True instead of blank=True, since in MySQL NULL can't be compared to anything else, so wouldn't flunk the unique test. But (since this is a CharField?), the lack of input was still saved as an empty string. Same thing if I tried both blank=True and null=True at the same time. I did full sqlreset's between these attempts, and verified through the mysql client that the changes had taken effect. Help? mysql Ver 14.12 Distrib 5.0.16, for pc-linux-gnu (i386) using readline 5.0 GNU/Linux, and the mysql-python stuff looks to be Version 1.2.1c3, Django trunk r2476. And this is all on Dreamhost. I did not have this problem with MySQL 4 while I was testing on my laptop. --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---