ValueError: badly formed hexadecimal UUID string while using Django model for UUIDField

Marcus Source

I am using Django==1.9 , My looks something as

from __future__ import unicode_literals

from django.db import models
import uuid

# Create your models here.
class Status(models.Model):
    id = models.UUIDField(default=uuid.uuid4, editable=False)
    comment = models.CharField(max_length=1000, unique=True)

When I run python migrate it throws me

  File "C:\Python27\Lib\", line 136, in __init__
    raise ValueError('badly formed hexadecimal UUID string')
ValueError: badly formed hexadecimal UUID string

Note that, The database table is not yet created in sqlite3.db so other answers for the similar looking question on Stack-Overflow suggests you should drop the database if exists and then migrate. But in my case the database doesn't exists as of now.

I tried most of the Stack-Overflow answer, some suggest use default='' , some says default=uuid.uuid4() etc. Nothing works for me, that is the reason why I created a new question. So, please don't link to answer just by blindly looking at the title !

The answers which I already referred to are as below: Python: How to solve the issue : 'badly formed hexadecimal UUID string' in Django

Django UUIDField modelfield causes error in Django admin: badly formed hexadecimal UUID string



comments powered by Disqus