Django 1.7现在要求设置迁移。不幸的是,在缺省字段值中使用lambdas或类似的函数打破了这个过程。生成UUID的默认值在django 1.7中打破了迁移,是否有解决方法?
我一个模型中有以下内容:
def make_uuid(type):
"""Takes an entity type identifier string as input and returns a hex of UUID2 with a
type identifier pre-pended for readability"""
return str(type)+str(uuid.uuid1().hex)
class Accounts(models.Model):
"""Model representing Accounts"""
PENDING_STATUS = 0
ACTIVE_STATUS = 1
SUSPENDED_STATUS = 2
CANCELLED_STATUS = 3
BETA_STATUS = 4
STATUS_CHOICES = (
(PENDING_STATUS, 'Pending'),
(ACTIVE_STATUS, 'Active'),
(SUSPENDED_STATUS, 'Suspended'),
(CANCELLED_STATUS, 'Cancelled'),
(BETA_STATUS, 'Beta'),
)
account_name = models.CharField(max_length=255)
account_uuid = models.CharField(max_length=34, default=partial(make_uuid,'AC'), db_index=True, unique=True)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
updated_by = models.ForeignKey(User, null=True, blank=True)
status = models.IntegerField(max_length=2, choices=STATUS_CHOICES, default=PENDING_STATUS)
局部中断的调用与下面的错误迁移过程:
ValueError: Cannot serialize: <functools.partial object at 0x10e5cf9f0>
There are some values Django cannot serialize into migration files.
我还需要自动生成的UUID,所以有没有人知道解决这个问题的办法,不会中断迁移?
谢谢!花了我一些时间来真正地考验这一点,并对结果感到满意,因为我被原始问题所摧残,但所有这些似乎都挺好,而且相当直截了当。 – Sologoub 2014-10-13 17:14:25