如何手动更改heroku数据库中的记录
how to manually change record in heroku database
我在 heroku 中托管了一个 rails 应用程序。我有一个带有内容栏的问题 table。内容列包含问题的词。因此,例如,如果您查询。 Question.first.content,你会得到 "Hello, how are you?"。我总共有8个问题。我想手动进入数据库并更改这些问题。
我用这个命令在 heroku 上尝试 运行 终端:
heroku pg:psql
并且我使用此查询来更改记录的内容列
UPDATE Questions
SET content="What country does this story orginate? (Japan)"
但是我收到此错误消息:
ERROR: column "What country does this story orginate? (Japan)" does not exist
LINE 2: SET content="What country does this story orginate? (Japan)"...
更改问题内容栏的正确查询是什么?
SQL 对字符串文字使用单引号,对标识符(例如 table 和列名)使用双引号,这就是您收到有关未知列的投诉的原因。修复很简单,对字符串文字使用单引号:
update questions set content = '...' where ...
有些数据库允许您对字符串使用双引号,但这是非标准的,应该避免。
原来我可以heroku run console
。进入控制台后,我可以进行活动记录查询,例如 Question.find(1).update_attributes(:content=>'how are you?')
并进行更新。无论出于何种原因 heroku run rails console
都没有使用活动记录查询更新记录,只是返回查询成功。
我在 heroku 中托管了一个 rails 应用程序。我有一个带有内容栏的问题 table。内容列包含问题的词。因此,例如,如果您查询。 Question.first.content,你会得到 "Hello, how are you?"。我总共有8个问题。我想手动进入数据库并更改这些问题。
我用这个命令在 heroku 上尝试 运行 终端:
heroku pg:psql
并且我使用此查询来更改记录的内容列
UPDATE Questions
SET content="What country does this story orginate? (Japan)"
但是我收到此错误消息:
ERROR: column "What country does this story orginate? (Japan)" does not exist
LINE 2: SET content="What country does this story orginate? (Japan)"...
更改问题内容栏的正确查询是什么?
SQL 对字符串文字使用单引号,对标识符(例如 table 和列名)使用双引号,这就是您收到有关未知列的投诉的原因。修复很简单,对字符串文字使用单引号:
update questions set content = '...' where ...
有些数据库允许您对字符串使用双引号,但这是非标准的,应该避免。
原来我可以heroku run console
。进入控制台后,我可以进行活动记录查询,例如 Question.find(1).update_attributes(:content=>'how are you?')
并进行更新。无论出于何种原因 heroku run rails console
都没有使用活动记录查询更新记录,只是返回查询成功。