Transfer database to Heroku - ruby-on-rails

I am trying to transfer my database to Heroku but I with no luck. I followed all steps in this guide: https://devcenter.heroku.com/articles/getting-started-with-rails4
I run heroku run rake db:migrate and it says Runningrake db:migrateattached to terminal... up, run.8685.
After I run heroku open I have access only to empty database and when I try to access some data, error shows: Completed 500 Internal Server Error in 25ms ActionView::Template::Error (undefined method id for nil:NilClass): So, there is no data present online.
What could be a problem? Thank you.
EDIT1:
When I go to a link https://postgres.heroku.com/databases/my-database-name I see this:
Statistics
Plan Dev
Status available
Data Size 6.6 MB
Tables 5
PG Version 9.2.5
Created October 22, 2013 16:45
It says there are 5 tables present and that's true. The problem is it seems these tables are empty. I don't see any option on Heroku website to browse database data. I checked with https://github.com/ddollar/heroku-sql-console, tried a couple of queries and database is empty.

Did your migration successfully ended??
Were you able to saw tables in your database??
If there is problem in your migration try to load it from schema
rake db:schema:load
please check your database status from postgres.heroku.com

Related

Can't access db after adding to Heroku

I can't access my Postgres tables since putting my app on Heroku. I checked the logs with heroku logs --tail and saw this error
ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR: relation "companies" does not exist
I've run as many different rake combinations of drop create migrate seed, and reset as I can think of with no luck.
I created a new endpoint on that app (/api/v1/testing/) and I was able to access that endpoint with no problem.
I am still able to access all of the tables on the db locally when I run rails s.
I don't know which files from my app would be helpful to solve this problem but I am happy to add any detail that would be helpful.
I'm guessing you didn't run:
heroku run rake db:migrate --app your_app_name
(replacing your_app_name, naturally.)

Heroku still referencing old database

I've provisioned and switched to a new database in my heroku app. And it seemed to work fine, but now I attempted to run the console and it had the data from my old database. I ran heroku addons:destroy <DATABASE_URL> --remote live and now the hobby-dev db has been destroyed and now when I try to run a query from the console I get PG::ConnectionBad: FATAL: role "fgedboaquoao" is not permitted to log in
Anybody know how I can stop my app from referencing the old database?
I had it hard coded in my production.rb to share the databases. that was the problem

ruby page on Heroku comes up with error: 'we're sorry but something went wrong'

Hi in the last week pushed a ROR rake task to prod and then ran the rake task to update some table fields in heroku.
Everything was seemed fine at the time but this week I did something that I hadn't done in the previous week of creating a new practice or editing one gives an error of 'we're sorry but something went wrong'
The error message I get from running --tail in the terminal says
Completed 500 internal server error in 34ms
ActionView::Template::Error (undefined method 'practices' for nil:NilClass);
This is my production application.
In the staging application I don't get this error.
The 2 environments are supposed to be the same.
Is a migration needed? or failing that how could I work out what is going wrong.
thanks
maggs
Run this command and try
heroku run rake db:migrate
Database
The 2 environments are supposed to be the same. Is a migration needed?
It depends on if you're using the same database in production & development
By default, Heroku gives you a blank PGSQL database, or you can override their DATABASE_URL config variable to use your own db:
heroku config:set DATABASE_URL=mysql://your_database
Recommendation
For now, I would recommend performing a heroku run rake db:migrate on your Heroku database, as this will provide the right data structure for your app
The real problem, though, is you're calling practices on an undefined object (nil:class). To ensure this is not a problem, you either need some logic such as:
unless #variable.nil?
# do something
end
or you need to ensure you're working with the correct data

Insert records to Heroku database

How can I insert new records to Heroku database. I have successfully uploaded my application and database structure. Now I need to insert some records so it could work. I tried to use seeds.rb but without any success. db:push and db:seed don't give any success. The database is always empty. Is there any heroku tool available which I could use to see database structure and insert data?
Thank you.
You have a few options. You can run heroku run rake db:seed.
Or assuming Postgres, try
heroku pg:psql
And run your SQL commands from there. See here for more.
I was also able to connect my IDE to my databases on Heroku. I am using RubyMine, so it was a matter of using the right JDBC URL to make that happen.
You can use below command for insert record to Heroku server
heroku run rails c
Example:-
suppose you have one table is employee and field are first_name.
Now open a command line and call this command
heroku run rails c
After call insert command
Employee.create(first_name: "admin")

Why do I get "We're sorry, but something went wrong." after restoring via pgbackups:restore with no migrations

This one took me a while to figure out. It's pretty tricky and seems like a bug in Heroku, so I will post my own answer in case it helps someone.
Scenario:
Rails application using postgresql adapter works fine on localhost.
All migrations are complete.
Deploying to Heroku via "git push heroku master" successfully updates Heroku instance.
Heroku PGBackups addon is installed and works fine.
pg_dump was used to generate a local db dump, and the file uploaded to an accessible internet location.
Problem:
After running
heroku pgbackups:restore DATABASE_URL 'http://mywebsite.com/pgbackup.dump'
I get the "something went wrong" message. Strange, considering all that happened was a database load, a database whose data works fine on the local machine. No migrations were performed, everything has been committed previously, no code updates... Only data in the database was changed, so why does the app no longer work if just data in the database changed?
Checking the heroku logs shows that it can't find tables that are clearly there. Lines like:
ActionView::Template::Error (PG::UndefinedTable: ERROR: relation "users" does not exist
Verifying with heroku pg:psql just makes the situation even stranger, because doing select * from users brings back the real results. Even performing a heroku restart at this stage won't get rid of the problem. I also tried combinations of that with heroku pg:reset and heroku run rake db:migrate.
Why does updating data in the database shut down the app?
Solution:
Run the pgbackups:restore as originally intended (and get error).
Run heroku restart.
Run heroku pg:psql (profit).
For some reason, it seems necessary to restart and then pg:psql before the database works after a pg:restore.
Even though pg:psql will gladly show that the tables are indeed there (contrary to the log messages), the app won't work until the dyno is restarted (and then it STILL won't work), not until you pg:psql.
As far as I know, pg:psql only establishes a connection to the remote database, and should not have any consequence on the state of the database server (though it seems it does).

Resources