Ussing uuid as a default value for a field results in the following migration:
class Student(peewee.Model):
...
uuid = UUIDField(default=uuid.uuid4, unique=True)
class Meta:
table_name = "student"
def forward(old_orm, new_orm):
student = new_orm['student']
return [
# Apply default value UUID('e942f2c0-9fd8-4d1e-86ac-5fae12451163') to the field student.uuid,
student.update({student.uuid: UUID('e942f2c0-9fd8-4d1e-86ac-5fae12451163')}).where(student.uuid.is_null(True)),
]
There's two issues here:
it uses the UUID object, which is not imported
instead of calling the uuid4 function to generate a random uuid for each entry, it uses a single one for all of those, causing an error with Unique constraint
Ussing uuid as a default value for a field results in the following migration:
There's two issues here:
UUID
object, which is not importeduuid4
function to generate a random uuid for each entry, it uses a single one for all of those, causing an error with Unique constraint