1

I am getting an ActiveRecord PGError on Heroku not locally. The error message from the Heroku Logs is:

ActiveRecord::StatementInvalid (PGError: ERROR: column items.user_id does not exist LINE 1: SELECT "items".* FROM "items" WHERE ("items".user_id = 4) OR

This code works locally (SQLite) but not on Heroku (postgresql) so I have been reading about the differences. At first I thought that it was a case issue as I recognised that it should be User_ID -- but now I'm not sure, it's something about "items" that isn't quite right and I can't work out exactly what it is.

As I said this works absolutely fine on my local machine, it's only on heroku and postgres that the problem comes up.

Thanks in advance.

3 Answers 3

1

It appears that your database does not have the 'user_id' column in the items table. This could be because your migration has not been run recently, or perhaps you have edited an existing migration rather than making a new migration to add this column.

Do you care about your data on heroku at the moment? If not you can use Taps to take whatever you have in your local database and set Heroku's database to a (virtual) synchronized copy of it. On your local machine from your project's directory:

heroku db:push

This will wipe your heroku database so use this wisely.

5
  • i did do a heroku rake db:migrate, and rather than heroku db:push i did a heroku db:pull to bring down my data and make sure it worked locally, it did, it worked fine locally just not on heroku
    – toast
    Jan 4, 2011 at 16:03
  • what data type is that column? You're using sqlite locally - try moving to postgres locally so you can see what is going on? Or try heroku db:reset
    – stef
    Jan 4, 2011 at 16:32
  • its an integer. I think that going forward i will have to change the development to postgres, i never realised that what heroku used, but for the time being I am pretty sure that if i move to postgres localy all that will happen is that i will have the problem locally. I could try heroku db:reset but not completely sure why i would i just don't think the problem lies with the data in the database.
    – toast
    Jan 4, 2011 at 17:00
  • yeah - I had to do the same. If you're on a mac make sure you use homebrew. Good luck.
    – stef
    Jan 4, 2011 at 18:17
  • many thanks.... i am still left with this problem whether i move to postgres locally or not, if anyone has any ideas....
    – toast
    Jan 4, 2011 at 19:30
0

Try restarting the app, using the following command:

heroku restart
0

It was a case issue after all - postgres does (I believe) a downcase on everything before sending it to the db -- my user_id was actually called, inexplicably, User_ID; after migration everything is working -- thanks to those that helped.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.