Hello I just ran heroku run rails c and heroku ran it on ⬢ immense-spire-28000 which is my staging database not infinite-38185. Any ideas how my production application got connected to my staging database and how I can switch it back?
Related
After deploying rails project on Heroku,I tried to get into the database console but when i run:
$ heroku run rails db
it is asking for password:
Password:
I forget the password,now i want to create table in database, any solution to setup password again??
heroku pg:psql is the canonical (and faster!) way to connect to heroku db.
The reason heroku run rails db doesn't work is because what it does is it creates a one-off process on Heroku with your codebase and runs rails db command there. rails db depends on $RAILS_ENV environment variable to fetch db credentials from config/database.yml which doesn't work on Heroku.
If you must know your Heroku db password you can get it from heroku config:get DATABASE_URL
I have postgresql setup for my production schema in database.yml. I was able to successfully run RAILS_ENV=production rake db:migrate but when I do do RAILS_ENV=production rails console, it hangs. Never gives me the console prompt.
I've also tried bundle exec rails console production but didn't help.
Output:
Connecting to database specified by database.yml
...hangs after this.
Running rails 3.2.11 on ruby 2.1.2. I have rbenv and rbenv-gemsets installed.
To run the rails console in the production environment you need to pass the name of the environment after the command. The actual command is as follows.
rails console production
If that doesn't work, try restarting your PostgreSQL server and try again. It could be that you have crossed the number of possible connections with the PostgreSQL database.
I have facing problems with migrating data to my heroku app which has Postgresql as database for my hosted site(Production). At my development site i have rails 3.2.13 with Sqlite3 as database. I have followed Ruby on rails Tutorial by Michael Hartl
i have used git push heroku to update my site at heroku. i also want to update database along with data. But heroku run rake db:migrate migrates schema not data. I tried db:push to push data to heroku but i get error
dependency.rb in 'to_specs' :Could not find sequel (~) 3.20.0
also i have searched and found that i should first my sqlite data to dump.sql and then run
heroku pg:psql HEROKU_POSTGRESQL_COLOR --app app_name < file.sql as answered in https://stackoverflow.com/questions/15371394/...
but it failed with
the local psql command could not be located
please tell me what i am doing wrong. or what is the right way to update heroku postgresql with my development sqlite3 data.
Thanks in Advance
It is not a good idea to fill the production database with the data that you have now in the developement database. Because, if you have problems with your production database in the future, and you need to refill it again, your development db may changed (e.g dropped), and you are not going to be able to do it again.
For this need, Rails provides seeds in db/seeds.rb file. You should create all the neccessary objects there.
Then when you push your code to Heroku, Heroku is going to prepare the database, create the schema, and seed it. If you need to seed the db manually, you can run bundle exec rake db:seed, if you want to run it in Heroku: heroku run bundle exec rake db:migrate
I just pushed my rails app to heroku, I actually have some fake data locally that I directly inserted into my table through rails console.
What is the equivalent of that in heroku, the tables are configured on heroku but there is no data.
I don't want to create a seed.rb in my db and then push it to github and then run rake db seed on heroku
can i do it manually?
You can enter your application console on heroku with:
heroku run rails console
Check out this gem. It is all ready dependency for heroku gem. With it bundled in your app you can do stuff like:
heroku db:pull
heroku db:push
Commands are quite self explanatory.
I had a working Active Admin app working on my local server, but after pushing to Heroku all my database tables are empty. I tried running heroku run rake db:migrate and then heroku restart but these both accomplished nothing. The tables are there, but they are empty.
Thanks!
If you want to have your Heroku app have the same database as local then you would you need to push your local database via heroku db:push to Heroku. This will replace the contents of the tables on Heroku with your local copy so use it carefully.
EDIT: heroku db:push is now heroku pg:push, the former is deprecated.