Here is a class from models.py:
class Shop(models.Model):
...
code = models.CharField(max_length=4, default=generate_random_code())
As you can imagine, generate_random_code()
always return a different string.
The problem is, Django migration engine is lost because everytime I make a python manage.py makemigrations
, I get a new modification Alter field tablet_code on shop
. I suppose this is because the function is executed, but it should not, so Django thinks I modified the code.
How would you solve this? Thanks.