PGError: Error: column of relation does not exist

2020-03-01 04:03发布

问题:

I'm trying to change the value of a column "isGroup" to the value "public".

I created a migration:

Post.connection.execute("update Posts set isgroup='public'")

However, I get the following error:

PGError: ERROR:  column "isgroup" of relation "posts" does not exist

I had unfortunately ran the column creating migration at the same time as the connection.execute migration. However, the "isGroup" column does exist on Heroku, so it is weird that the column is not showing as appearing.

Any advice?

回答1:

If you are sure that column isGroup exists, then you should quote it like:

UPDATE posts SET "isGroup" = 'public'

Note that PostgreSQL by default folds all unquoted named to lowercase.

To avoid this confusion and necessity to quote, you might want to rename isGroup to isgroup using ALTER TABLE ... RENAME COLUMN ....