简体   繁体   English

Django:psycopg2.errors.UndefinedColumn:“pages_page”关系的“page_image”列不存在

[英]Django: psycopg2.errors.UndefinedColumn: column “page_image” of “pages_page” relation does not exist

Here is a brief backstory.这是一个简短的背景故事。 I am using the Mezzanine CMS for Django.我正在为 Django 使用 Mezzanine CMS。 I created some models that inherited from the Mezzanine models.我创建了一些继承自夹层模型的模型。 This caused an issue in my Postgres database, where one object was present in two tables.这在我的 Postgres 数据库中导致了一个问题,其中一个对象存在于两个表中。 When I would try searching my site for a post, I would not get results from one table.当我尝试在我的网站上搜索帖子时,我不会从一张表中获得结果。

So, here is where I believe I messed up.所以,这就是我认为我搞砸的地方。 I reverted my models to how they were before this issue.我将我的模型恢复到出现此问题之前的状态。 This meant that there was still a table in my database for those models, so my search function still wouldn't work.这意味着我的数据库中仍然有这些模型的表,所以我的搜索功能仍然不起作用。 I wanted this relation gone, so I did something very stupid and deleted the entire database.我希望这种关系消失,所以我做了一些非常愚蠢的事情并删除了整个数据库。 This was fine for my local development, because I just recreated the database and migrated.这对我的本地开发来说很好,因为我只是重新创建了数据库并进行了迁移。

When I try deploying this project of mine with the newly created postgres database onto DigitalOcean, I get to this command:当我尝试使用新创建的 postgres 数据库将我的这个项目部署到 DigitalOcean 上时,我得到了这个命令:
$ python manage.py createdb --nodata --noinput which gives me the error: $ python manage.py createdb --nodata --noinput这给了我错误:

psycopg2.errors.UndefinedColumn: column "page_image" of "pages_page" relation does not exist
LINE 1: UPDATE "pages_page" SET "page_image" = '', "keywords_string"...

I looked up a few threads on this error, and tried this solution that did not work:我在这个错误上查找了几个线程,并尝试了这个不起作用的解决方案

python manage.py shell

>>> from django.contrib.contenttypes.models import ContentType
>>> ContentType.objects.all().delete()

I have also tried the suggestion in the error LINE 1: UPDATE "pages_page" SET "page_image" = '', "keywords_string"... .我也尝试过错误LINE 1: UPDATE "pages_page" SET "page_image" = '', "keywords_string"... The weird thing was, I saw the page_image column inside the pages_page table before running this command.奇怪的是,在运行此命令之前,我在pages_page表中看到了page_image列。

I do not know what code may be helpful in this case.我不知道在这种情况下哪些代码可能会有所帮助。 I do not know how to troubleshoot this issue.我不知道如何解决这个问题。 How can I further troubleshoot this issue of mine?我怎样才能进一步解决我的这个问题?

I figured this issue out.我想通了这个问题。 It has something to do with the EXTRA_MODEL_FIELDS option in the settings.py file.它与settings.py文件中的EXTRA_MODEL_FIELDS选项有关。 I'm still not sure why that causes an issue, but here is my EXTRA_MODEL_FIELDS code:我仍然不确定为什么会导致问题,但这是我的EXTRA_MODEL_FIELDS代码:

EXTRA_MODEL_FIELDS = (
     (
...,
     (
        "mezzanine.pages.models.Page.page_image",
        "ImageField",
        (_("Featured Image"),),
        {"blank": True, "upload_to": "uploads/blog"},   
     ),
...
 )

What I did that caused my issue to go away is as listed below:我所做的导致我的问题消失的操作如下:

  • I deployed with the createdb --nodata --noinput command commented out.我用已注释掉的createdb --nodata --noinput命令部署。
  • I continued the deployment process我继续部署过程
  • Once I got to deploying the website, I just ran migrations again一旦我开始部署网站,我就再次运行迁移
  • The page_image column was automatically added page_image列已自动添加

Now everything works fine!现在一切正常! I don't know how much help this answer might be, but I can always go more into depth if someone wants to chat about their issues.我不知道这个答案可能有多大帮助,但如果有人想谈论他们的问题,我总是可以更深入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 (psycopg2.errors.UndefinedColumn) 列“名称”不存在 - (psycopg2.errors.UndefinedColumn) column "name" does not exist ProgrammingError:(psycopg2.errors.UndefinedColumn)关系“task_fail”的列“execution_date”不存在 - ProgrammingError: (psycopg2.errors.UndefinedColumn) column "execution_date" of relation "task_fail" does not exist psycopg2.errors.UndefinedColumn:列 - psycopg2.errors.UndefinedColumn: column 没有这样的表:pages_page - no such table: pages_page ProgrammingError: (psycopg2.errors.UndefinedColumn),同时使用 sqlalchemy - ProgrammingError: (psycopg2.errors.UndefinedColumn), while working with sqlalchemy psycopg2 - UndefinedColumn:关系的列“日期时间”“<table_name> “ 不存在</table_name> - psycopg2 - UndefinedColumn: column "datetime" of relation "<table_name>" does not exist psycopg2.errors.UndefinedTable:关系“练习”不存在 - Django 测试 - psycopg2.errors.UndefinedTable: relation “exercises” does not exist - Django Testing psycopg2.errors.UndefinedTable:关系“authentication_author”不存在:Django v4 - psycopg2.errors.UndefinedTable: relation "authentication_author" does not exist: Django v4 Psycopg2.errors.Undifinedcolumn:列不存在 - Psycopg2.errors.Undifinedcolumn : column does not exist psycopg2.errors.UndefinedTable:关系不存在(连接表) - psycopg2.errors.UndefinedTable: relation does not exist (join table)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM