DEV Community

sium_hossain
sium_hossain

Posted on

django.db.utils.ProgrammingError: column <name> of relation "app_name__table" already exists

Sometime we messed up with django migration and migrate process. Deleting migration file and run python manage.py makemigrations and python manage.py migrate solve the issue by undo previous migration or we can say that it takes us to previous migration state. But I faced one kind of situation where already a column created by a migrations and I saved some data in this column which was already created. And if i want to delete a migration file and want to go back previous situation django make sure that it doesn't happened because column is already created and I want to add this column again. And in this situation django will throw a error something like that 👇
error message

And I can't delete all my data and make migrations from zero. Because I'm in now production mode and have some data in my database. So I run this command and it's help me to overcome from this situation. And the magical command is 🧞-

python manage.py migrate --fake <put your app name>
Enter fullscreen mode Exit fullscreen mode

Discussion (0)