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

新手Web编程遇报错:post_post表无publishing_date字段求解决

解决table post_post has no column named publishing_date错误
  • 先检查你的模型文件(比如models.py)里的Post类,确认是否正确定义了publishing_date字段,示例:

    class Post(models.Model):
        # 其他字段...
        publishing_date = models.DateTimeField(auto_now_add=True)
    

    确保字段名无拼写错误,字段类型符合需求。

  • 生成迁移脚本:打开终端进入项目根目录,运行命令:

    python manage.py makemigrations
    

    这一步会识别模型变化,生成对应的数据库修改脚本。

  • 应用迁移到数据库:接着运行命令:

    python manage.py migrate
    

    执行后数据库表post_post就会新增publishing_date字段。

  • 如果上述步骤没生效(比如迁移记录混乱),测试阶段可按以下操作重置:

    • 删除对应app下migrations文件夹里除__init__.py外的所有文件
    • 删除项目根目录的数据库文件(比如db.sqlite3)
    • 重新执行makemigrations和migrate命令

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.23 11:39:18