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_total
nullable - makemigrations + migrate
- set
price_total
equal toprice
for example throughdjango shell
- make
price_total
not 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?