Open orporat opened 9 years ago
Hi @cheerzorpo, I'll look into this. Thanks!
I think you can get around the migration error with
import uuid
class MyModel(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4)
A better error message is probably necessary, also the default django fields let you define date time callables for new time fields, something like that isn't necessary but could be nice.
Hi @budlight,
This would require me to add default
back every time I create a migration and take it off after the migration is applied, in order that I wouldn't have problems with admin inlines.
Plus, the exception says:
ValueError: Explicit UUID required unless either `null` is True or `auto_add` is given.
I did set auto_add=True
in my example, so isn't this a bug anyway? :P
Thanks
not the same thing?
auto_add=True
in contrast to default
doesn't result in problems with admin inlines, but the exception in the migration process is being thrown even though the field has auto_add=True
(which by the exception message doesn't supposed to happen)
I am having the same problem on Django 1.7 during migration. Adding a default value does fix the problem.
It looks like during the migration the migration process the auto_add parameter gets dropped (maybe has to do with deconstruct, I am not sure) but here is a dump of the value of auto_add and kwargs during a migration if it helps: True <-> {'default': <function uuid4 at 0x28c0cf8>, 'primary_key': True} False <-> {u'default': <function uuid4 at 0x28c0cf8>, u'serialize': False, u'unique': True, u'editable': False, u'primary_key': True} False <-> {u'default': <function uuid4 at 0x28c0cf8>, u'serialize': False, u'unique': True, u'editable': False, u'primary_key': True} False <-> {u'default': <function uuid4 at 0x28c0cf8>, u'serialize': False, u'unique': True, u'editable': False, u'primary_key': True} False <-> {u'default': <function uuid4 at 0x28c0cf8>, u'serialize': False, u'unique': True, u'editable': False, u'primary_key': True}
Hi,
I'm testing django-pgfields 1.5.0a1 with Django 1.7rc2 and I have a problem with admin inlines. These are my models:
And here's my admin configuration:
As you might notice, in the models definition I dont have
default=uuid.uuid4
on theid
fields but I do haveauto_add=True
. This is because setting a default on these fields seems to be causing inline rows in the admin to be pre-filled with the uuid4 values when the form is rendered. When the form is saved, Django marks these inlines as 'changed' effectively trying to create them as new objects thus triggering form validation for all of these inlines requireing values for all form fields that doesn't havenull=True, blank=True
(e.g. "name" in this case). This happens even if the id field is hidden.With the models' definition mentioned above inlines work well, but when I try to apply a migration, this is the result (I've applied it once with
default=uuid.uuid4
and then removed it):Help, please :)
Thanks very much!