Opened 10 years ago
Closed 10 years ago
#24631 closed Bug (invalid)
UUIDField makemigration error
Reported by: | Muhamad A. | Owned by: | nobody |
---|---|---|---|
Component: | Migrations | Version: | 1.8 |
Severity: | Normal | Keywords: | migration |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
As I'm using UUIDField to generate a primary key, when I make migration it returns the following
ValueError: Cannot serialize: UUID('613d3463-b9d6-4bf1-9b62-1e31598b2700') There are some values Django cannot serialize into migration files. For more, see https://docs.djangoproject.com/en/1.8/topics/migrations/#migration-serializing
Using the following in models.py
from uuid import uuid4 uuid = models.UUIDField(primary_key=True, default=uuid4(), editable=False)
I managed to make this work by using default=uuid4().hex but the value in the migration file is that generated value
Note:
See TracTickets
for help on using tickets.
Re-read the documentation: https://docs.djangoproject.com/en/1.8/ref/models/fields/#uuidfield
Note that a callable (with the parentheses omitted) is passed to default, not an instance of UUID.