[英]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:我所做的导致我的问题消失的操作如下:
createdb --nodata --noinput
command commented out.createdb --nodata --noinput
命令部署。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.