首页 > 解决方案 > Column Already Exist Error on Django Rest Framework on Heroku Migration

问题描述

I have updated my model, but I couldn't do the migrations, the problem is:

I am getting an error like: column "blah blah" of relation "blah blah blah" already exists

The mentioned column should exist in DB, but it shouldn't exist on migration file because I did not do any addition or modification about that model field and it was already successfully created in one of the previous migrations, even used frequently without any error.

When I do the migration with --fake, this time it doesn't create the really unexisting field of migration file which is defined with that model update.

Deployed on Heroku, it may be caused by rollbacks of code layer, since after rollbacks code gets to older versions but DB stays same.

What is the best way without losing any data from production DB?

Following is a screenshot of the bash; timezone, endtime and start time fields already exist on model and DB before this migration, created on one of the previous successful migrations

Click here to screenshot of Heroku Bash when I try to run migrations

Thanks

标签: djangopython-3.xherokudjango-rest-frameworkdjango-migrations

解决方案


应该在 Heroku 上运行 makemigrations。在本地执行,然后提交结果、部署,然后仅运行迁移。

事实上,你已经完全不同步了。如果您没有任何需要保留的数据,最简单的方法是删除您的数据库并重新开始。


推荐阅读