creating an id and trying to insert a record with it, but having duplication error.
django.db.utils.IntegrityError: (1062, "1062 (23000): Duplicate entry '715683160' for key 'projects_project.PRIMARY'", '23000')
import random
def makeUniqueLongId():
return random.randint(100000000, 999999999)
class Project(models.Model):
id = models.BigIntegerField(unique=True, primary_key=True, default=makeUniqueLongId(), editable=False)
...
How can I prevent id duplication? Is unique=True not enough to return new id with makeUniqueLongId()