[Answer]-How to set the default value for existing entries when adding a new column?

2👍

You need to use Django’s migrations, which will allow you to add the field to the database.

In short, you make the change to your model, create a migration with manage.py makemigrations, and then run it with manage.py migrate.

0👍

Sounds like you need to migrate your database after adding the new column. Its like when you use the syncdb command to do the “create table” commands when first creating your database, the migrations will write “alter table” changes to your database.

https://docs.djangoproject.com/en/1.8/topics/migrations/

0👍

It turns out I had missed that the migrate command requires the app name. So, I had to run the command like this:

manage.py makemigrations app_name

-1👍

By default BooleanField column is False, you don’t need to specify anything. Just run python manage.py migrate. It should work.

👤Ajai

Leave a comment