toast
toast

Reputation: 592

ActiveRecord PGError on Heroku not locally

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.

Upvotes: 1

Views: 1358

Answers (3)

toast
toast

Reputation: 592

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.

Upvotes: 0

user1857737
user1857737

Reputation: 1

Try restarting the app, using the following command:

heroku restart

Upvotes: 0

stef
stef

Reputation: 14268

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.

Upvotes: 1

Related Questions