I have a model:
class Model(models.Model):
price = models.DecimalField(...)
There are already Model objects in production database.
Now I add price_total field to this model which can't be null.
class Model(models.Model):
price = models.DecimalField(...)
price_total = models.DecimalField(...)
I want this price_total to be equal to price right after migration.
Something like:
price_total = models.DecimalField(default=this_object.price,...)
Is it possible to do it somehow?
The only thing I know about is:
- make
price_totalnullable - makemigrations + migrate
- set
price_totalequal topricefor example throughdjango shell - make
price_totalnot nullable - makemigration + migrate
But this way has multiple disadvantages, you can forgot to do that in production, it has many steps etc...
Is there a better way?