﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
31531	Loaddata fixtures with UUID as primary key	max13fr	nobody	"Hello,

I have an issue with Django 3. I use an UUID field as primary key. When I'm reloading fixtures, I got the error ""UNIQUE constraint failed: api_test.id"".

It's seem that loaddata not detecting if the primary key already existing in DB so instead of an update, it tries to insert again the line with the same primary key.
I'm wondering if the issue doesn't come from the lack of dash in the database (sqlite) : ""724ea59910a249a1be2fc1fcb04d003e"" instead of ""724ea599-10a2-49a1-be2f-c1fcb04d003e"".

Important note : I converted the default id field to UUID with in a specific migration (but the table was empty), I don't know if it can also be the source of the issue.

Here the example:

api/models.py :

{{{
class Model Test(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    name = models.CharField(max_length=100)
}}}

api/fixtures/initial_data.json :

{{{
{
    ""model"": ""api.Test"",
    ""pk"": ""724ea599-10a2-49a1-be2f-c1fcb04d003e"",
    ""fields"": {
        ""name"": ""Test 1""
    }
}, {
    ""model"": ""api.Test"",
    ""pk"": ""6bcb72f0-099b-416d-8b2c-fcd0bef76cbf"",
    ""fields"": {
        ""name"": ""Test 2""
    }
}
}}}

{{{
python manage.py loaddata initial_data
}}}

{{{
django.db.utils.IntegrityError: Problem installing fixture 'api/fixtures/initial_data.json': Could not load api.Test(pk=724ea599-10a2-49a1-be2f-c1fcb04d003e): UNIQUE constraint failed: api_test.id
}}}

Thanks in advance
Max"	Bug	closed	Database layer (models, ORM)	3.0	Normal	duplicate		Mark Dawson	Unreviewed	0	0	0	0	0	0
