You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Django+Heroku Postgres提交表单报ProgrammingError错误求助

解决Django+Heroku Postgres提交文章时的ProgrammingError错误

错误提示column "title" of relation "main_post" does not exist,核心原因是你的Post模型定义了title字段,但Heroku上的Postgres数据库表未同步该字段,数据库迁移操作未正确执行。

解决步骤:

  • 本地生成迁移文件
    在项目根目录执行命令,生成对应Post模型字段的迁移文件:

    python manage.py makemigrations
    

    执行后检查main/migrations目录,确认生成了包含title、description字段创建逻辑的新迁移文件。

  • 推送迁移文件到Heroku
    将迁移文件提交至Git仓库并推送到Heroku:

    git add main/migrations/
    git commit -m "Add Post model fields migrations"
    git push heroku main
    
  • 在Heroku上执行迁移
    通过Heroku CLI运行迁移命令,同步数据库结构:

    heroku run python manage.py migrate
    

迁移失败时的额外处理:

  • 查看Heroku日志排查错误:
    heroku logs --tail
    
  • 若存在无效迁移记录,可重置迁移(注意:此操作会清空数据库数据,谨慎使用):
    heroku run python manage.py migrate main zero
    heroku run python manage.py migrate
    

内容的提问来源于stack exchange,提问作者Franciso Reyna

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 21:10:39