Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to manually change record in heroku database

I have a rails app hosted in heroku. I have a Questions table with a content column. The content column contains the word of a question. So for example if you queried. Question.first.content, you would get "Hello, how are you?". I have 8 questions in total. I would like to manually go into the database and change these questions.

I tried running the terminal on heroku with this command:

heroku pg:psql

and I used this query to change the content column of a record

UPDATE Questions
SET content="What country does this story orginate? (Japan)"  

However I get this error message:

ERROR: column "What country does this story orginate? (Japan)" does not exist
LINE 2: SET content="What country does this story orginate? (Japan)"...

What is the right query of changing the question's content column?

like image 334
user3266824 Avatar asked May 16 '15 18:05

user3266824


People also ask

How do I reset my Heroku database?

Select the database you want to reset. Click on a settings button in the right upper corner. Click "Reset Database" as shown below: type in "RESET" and press ok.

How do I access my Heroku Postgres database?

All Heroku Postgres databases have a corresponding Heroku application. You can find the application name on the database page at data.heroku.com. Your database is attached to the Heroku app and is accessible via an app config var containing the database URL, even if you host no code in the application itself.


2 Answers

It turns out I can do heroku run console. Once in the console I can do active record queries such as Question.find(1).update_attributes(:content=>'how are you?') and it updates. For whatever reason heroku run rails console did not update the record with active record queries but just returned that the query was successful.

like image 114
user3266824 Avatar answered Sep 25 '22 23:09

user3266824


SQL uses single quotes for string literals and double quotes for identifiers (such as table and column names), that's why you're getting a complaint about an unknown column. The fix is simple, use single quotes for the string literal:

update questions set content = '...' where ...

Some databases let you use double quotes for strings but that's non-standard and should be avoided.

like image 44
mu is too short Avatar answered Sep 24 '22 23:09

mu is too short