'Why is Django setting default values to all existing model attributes?

I have a model called Book. Book has the following attributes: title, release_date and condition where condition has a default value set to "new". I created some of Books in django admin site. After I created a new attribute for this model called category which it has a default value set to "No category". Why is django setting category = "new" to all existing books instead of "No category". With the books that I add after the migration Django set them correctly. Why is this happening.

class Book(models.Model):
class ConditionType(models.TextChoices):
    USED = "Used"
    NEW = "New"

class Category(models.TextChoices):
    ACTION_ADVENTURE = "Action and Adventure"
    CLASSIC = "Classic"
    MYSTERY = "Mystery"
    FANTASY = "Fantasy"
    HORROR = "Horror"
    LITERERY_FICTION = "Literary Fiction"
    SCIENCE_FICTION = "Science Fiction"
    NON_FICTION = "Non-Fiction"
    NO_CAT = "No category"

title = models.CharField(
    max_length=150,
    null=False,
)
release_date = models.DateField()
condition = models.CharField(
    max_length=12,
    choices=ConditionType.choices,
    default=ConditionType.NEW,
)
category = models.CharField(
    max_length=40,
    choices=Category.choices,
    default=Category.NO_CAT,
)

After the first migration I added the category field btw.



Solution 1:[1]

As far as I know, django needs some field value (as NULL) for the existing rows in database. Maybe you accidentally typed "new" when it asked you for filling those blank field values?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mammadali Mammadaliyev