In building projects using Django, one thing that I have realized about database migrations is that things may appear simple until the moment one alters an existing model.
For example, in developing an inventory management app for my project recently, I experienced a migration problem, which, although small, helped me understand how migrations work within Django and in particular, when adding unique constraints to existing databases.
I would like to document this problem since someone else may have experienced the same thing.
The Initial Inventory Model
At the beginning, my Product model was simple.
from django.db import models
class Product ( models . Model ): name = models . CharField ( max_length = 100 ) buying_price = models . DecimalField ( max_digits = 10 , decimal_places = 2 ) selling_price = models . DecimalField ( max_digits = 10 , decimal_places = 2 ) stock_quantity = models . PositiveIntegerField ( default = 0 ) low_stock_threshold = models .…