【问题标题】:django python - relation does not existdjango python - 关系不存在
【发布时间】:2016-01-05 14:12:12
【问题描述】:

我正在运行 django 1.7 和 python 2.7。

在我的 postgressql 数据库中,我有一些多余的表。我现在相信,在我升级到 django 1.7 之前,我之前更改了许多表的名称时,多余的表就变得多余了。多余的表名中没有任何数据。

在我检查了我的迁移并在我的项目中搜索了多余的表名但没有找到任何引用之后,我删除/删除了这些表。

我可以更新现有记录并添加新记录,但删除表后,我无法删除现有记录。

现有且正确的表名是core_namedetails。这是存储所有用户名详细信息的表。

我在 postgressql 数据库中删除的表是 core_resume_name_details

这是我在尝试从 core_namedetails 中删除记录时遇到的错误:

ProgrammingError at /resume_details/name_details/delete/251/
relation "core_resume_name_details" does not exist
LINE 1: DELETE FROM "core_resume_name_details" WHERE "core_resume_na...
                    ^
Request Method: GET
Request URL:    http://127.0.0.1:8000/resume_details/name_details/delete/251/
Django Version: 1.7.2
Exception Type: ProgrammingError
Exception Value:    
relation "core_resume_name_details" does not exist
LINE 1: DELETE FROM "core_resume_name_details" WHERE "core_resume_na...

我已经运行了makemigrationsmigrate。不返回任何问题。

我已经搜索了 google & SO,但没有发现任何信息可以说明我的错误。

有人对此问题有任何解决方案吗?

【问题讨论】:

    标签: python django postgresql python-2.7 django-1.7


    【解决方案1】:

    问题是您的模型正在寻找core_resume_name_details 表。可能您在将此表重命名为 core_name_details 时丢失了迁移。 解决方案 - 将db_table = 'core_namedetails' 添加到模型的元数据中,或手动将表core_namedetails 重命名为core_resume_name_details

    【讨论】:

      【解决方案2】:

      问题是迁移文件损坏。我最终追踪了损坏的文件并修复了有问题的代码行。

      希望这对某人有所帮助。

      【讨论】:

        猜你喜欢
        • 2017-07-05
        • 2016-02-06
        • 2019-08-02
        • 2020-04-09
        • 2014-07-18
        • 2020-12-12
        • 1970-01-01
        • 2018-07-16
        • 2017-07-01
        相关资源
        最近更新 更多