Normal view

There are new articles available, click to refresh the page.
Before yesterdayRecent Questions - Stack Overflow

The same uuid is generated for different objects in Django

When I run a server on localhost I am able to add new objects in my postgre database through the Django admin panel, but only one for every table. When I try to add a second new object, it assigns the same UUID that has already been used. There is an example of model with UUID as primary key:

models.py

from django.db import models
from authuser.models import User
from django.utils import timezone
import uuid

class Thread(models.Model):

    idthread = models.UUIDField(default=uuid.uuid4(), primary_key=True, unique=True)
    date_created = models.DateTimeField(default=timezone.now)
    userid = models.ForeignKey(User, on_delete=models.DO_NOTHING)
    name = models.CharField()

    def __str__(self):
        return self.name

Only after restarting the server will assign a new unique UUID to objects that I would like to add.

❌
❌