1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] It is impossible to add a non-nullable field 'name' to table_name without specifying...

Discussão em 'Python' iniciado por Stack, Setembro 12, 2024.

  1. Stack

    Stack Membro Participativo

    I have added a following field in my already existing model:

    name = models.CharField(max_length=128, unique=True)


    But it is giving following prompt when applying migrations:

    It is impossible to add a non-nullable field 'name' to table_name without specifying a default. This is because the database needs something to populate existing rows.
    Please select a fix:
    1) Provide a one-off default now (will be set on all existing rows with a null value for this column)
    2) Quit and manually define a default value in models.py.


    I cannot set it's attributes to blank=True, null=True as this field is must. I cannot set it's default value as the field has to be unique. I also deleted all the previous data from that table. If I try to set it's default value in command prompt, it says plz select a valid option. How to fix it?

    Continue reading...

Compartilhe esta Página