makemigration detect error

107 views
Skip to first unread message

Er. Rv Ranga

unread,
May 6, 2017, 6:51:25 AM5/6/17
to Django users
 python manage.py makemigrations blog

You are trying to add a non-nullable field 'body' to post without a default; we can't do that (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 let me add a default in models.py
Select an option:

what is this and how we solve it

Vijay Khemlani

unread,
May 6, 2017, 8:26:14 AM5/6/17
to django...@googlegroups.com
You are adding a non-null field to a table, so the existing rows from
that table need a value to put in it to enforce the non-null rule.

If you select 1, you type that value, and it is used for all
previously existing rows in the table.
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/4fd75ea1-3963-45bb-8411-7e3edf7d960c%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

ad...@tradom.ca

unread,
May 6, 2017, 10:51:16 AM5/6/17
to django...@googlegroups.com
Hello,

I know somewhat about this situation.
I was a beginner some months ago :-)

the situation is :
you change something in a model (add a non-nullable field)
when you send « makemigrations" the ORM needs to get a value for the new fields just because it’s non-nullable
before modifying anything in the database.

choice 1 - you could enter a valid value directly in the terminal windows and the next time you add a new line in your database, you provide a value for this field and everything will goes well.

choice 2 - you stop the migrations and change the properties of your new field in the model itself (provide a default value, or transform the field in a nullable field)

hope it’s help!
see you

Dominique


ad...@tradom.ca
ad...@tradom.ca

Melvyn Sopacua

unread,
May 8, 2017, 10:07:33 AM5/8/17
to django...@googlegroups.com

Just curious - what is not clear about the language used here and what made it clear from the answers?

--

Melvyn Sopacua

Reply all
Reply to author
Forward
0 new messages