I'm trying to create a random string into my DB for users. It's a part of passwordless login.
So I have a field that is supposed to generate a random string. But I just found out it does not. It acctually generates same string over and over. Maybe each 5-10 min it will generate a new string for several minutes.
My model looks like this.
class Random(models.Model):
user = models.OneToOneField('CustomUser', on_delete=models.CASCADE)
random = models.CharField(max_length=25, default=uuid.uuid4().hex[:25].upper(), unique=True)
created_at = models.DateTimeField(auto_now_add=True)
Even though it's generating a 25 long string, it duplicates it over and over.
Since I have unique true, that results in next call for creating a string is not possible, since it's not unique.
How come it's creating unique each time?