Adding new field to existing database table in django python

Viewed 1293

I have a Postgresql database connected with my django application, Now I have a existing table in the database and want to add a new field to this table using the migrate command. But when I try to add this new field to my models.py and run makemigration and migrate commands, django says there are no new migrations to apply. Can you help me with how to add a new field to existing table.

2 Answers

Try running makemigrations command specifying your app name like this:

 python manage.py makemigrations myapp

and then try running migrate command

After a long research I got a solution as below:

pip install django-extensions

and add this in the install app of settings.py

INSTALLED_APPS = [
    'django_extensions'
]

Now, run migrations for your installed apps

python manage.py makemigrations your_app_name
python manage.py migrtate your_app_name

Done! See Your Database...

Related