简体   繁体   中英

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. 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. 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:
$ python manage.py createdb --nodata --noinput which gives me the error:

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"... . The weird thing was, I saw the page_image column inside the pages_page table before running this command.

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. I'm still not sure why that causes an issue, but here is my EXTRA_MODEL_FIELDS code:

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.
  • I continued the deployment process
  • Once I got to deploying the website, I just ran migrations again
  • The page_image column was automatically added

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM