Reputation: 1
I'm new to ruby development and I had a problem with the database when deploying the project on heroku
I used postgresql as a database. Test created an entry in the database using the name:string field. Then I made a migration and decided to check the performance locally.
<h1><%= @name.name %></h1>
Locally the database works correctly. But when deploying this project on heroku, it gives the following picture.
Logs:
Database on heroku after migration enter image description here
Upvotes: 0
Views: 69
Reputation: 129
Like said above, the problem is that your record does not exist in production. If you added it locally, it's normal that is has not been added when pushed to Heroku, as the Database is reset.
There are many ways to fix your problem, here are two:
You can use the seed file in the folder db/seeds
, in which you added your User.create!(id: 2)
and run:
heroku run rails db:seed -a name_of_your_app
Or you can run a rails console from which you User.create!(id: 2)
from Heroku to manually create that missing user:
heroku run rails c -a name_of_your_app
You should also learn how to read errors that get printed in the console, Record Not Found
could have happened locally and has not much to do with Heroku. You should be able to tell what the problem is rather quickly if you learn to do so.
Upvotes: 0
Reputation: 191
From your log screenshot, I could see that the error is ActiveRecord::RecordNotFound (Couldn't find User with id=2)
.
I am sure you're loading with something like User.find(2)
in WelcomeController#show
.
Just make sure User#2
exists or loading other existing User.
If it doesn't solve your issue, please let me know.
Good luck with your journey in learning Rails.
Upvotes: 1