django - 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
解决方案
你不应该在 Heroku 上运行 makemigrations。在本地执行,然后提交结果、部署,然后仅运行迁移。
事实上,你已经完全不同步了。如果您没有任何需要保留的数据,最简单的方法是删除您的数据库并重新开始。
推荐阅读
- azure - 在 Azure Devops 发布管道上的 Appsettings.Json 中添加数组元素通过魔术块配置转换
- java - Quarkus REST 服务异常处理
- reactjs - 使用 React(Django 后端)进行 axios 调用时出现 403 禁止请求
- azure - 将 Prefetch 与 Batch 一起使用会减慢 Azure 服务总线中的消息接收速度
- python - 图形故障 ttk 小部件
- android - 颤振 https 和 http 检查
- wordpress - 将多个 Wordpress 页面合并为 1 页
- javascript - 在 TypeORM 中添加 `updatedDate` 列而不使用 Typescript 装饰器`@UpdateDateColumn`
- spring-boot - SpringBoot 2.4.1 的 OAuth2.0 迁移
- shell - 通过 shell 脚本访问 SSH 和 git sync