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.)
Related
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
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
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")
Hey so I am following the One Month Rails guide to learning Ruby and I have hit a wall on one of the lessons. I have just finished uploading an image with Paperclip, and as I finished my work on my localhost and checked it on Heroku, something went wrong. The pin/image appears to have been pushed to my Heroku account, the only problem is that the username and password that works for my localhost:3000 won't work for my Heroku account. The same password should work for both, but for some reason something is wrong. I wish I could give you the action that is going on in my terminal, but the ruby rails is the only thing that has a continuous status flow. The problem may have been when I switched my password after not using my account on localhost for a few weeks, but i thought that once i "git pushed" that to heroku master, it would've synced. I have tried heroku run rake db:setup which didn't seem to do too much as well as wrestled by way through "Importing a Heroku Postgres Database with PG Backups", but I had some trouble working through that. Any ideas? Thanks for the help.
Your 'database.yml' should not be sent to Heroku, they take care of that, creating a new database.yml config file with the proper DB access details.
Try logging into your Heroku instance and deleting the file.
Edit: nevermind, assumed you were not able to connect to the DB, not to login into the website.
So if I'm understanding you correctly, you've deployed your application to Heroku and the login (to your application) that was working locally doesn't work on Heroku.
Deploying your application doesn't deploy data. Assuming you've run heroku run rake db:migrate then your database schemas will at least match.
At this point, you've got a couple of options.
Use a seeds.rb file which you can load with heroku run db:seed to setup some 'seed' data so that you can login.
Push your local database to Heroku - either via heroku db:push or using heroku pg:transfer provided by https://github.com/ddollar/heroku-pg-transfer
Use heroku run console to create your user account via the command line
User.create(email: 'someemail.com', password: 'somepassword', password_confirmation: 'somepassword')
I'd be inclined to go with the later option.
How did the user get in their in the first place? Perhaps going back to that step in the tutorial - just remember, if you are using rails console locally to use heroku run console on Heroku.
I'm running a Rails 3.09 Ruby 1.92 App on Bamboo stack on Heroku. The app works just fine in production mode running locally without problems. I'm trying to diagnose why the app won't run on Heroku. I'm getting a 500 Error Miscellaneous Server Error. Has anyone seen something like what's in the logs before?
This is my logs...
https://gist.github.com/2655795
Update: here's the updated log: https://gist.github.com/2655991
Update: I enabled config.whiny_nils = true in my production.rb file and now I am getting this error on Heroku but not running locally on my environment in production. I'm using Postgres locally.
G::Error: ERROR: null value in column "id" violates not-null constraint
: INSERT INTO "sessions"
I bet you're migrating from MySQL.
Your table doesn't have a sequence, what pg uses instead of autoincrement. Instead of creating your table's id column with "id" integer NOT NULL,, use "id" serial,. Postgres will mention it's creating a sequence for you, and you can run \d tablename in the command line to see it.
Log into Heroku and run the following:
rake db:sessions:clear
It looks like you may have old session data laying around.
If you haven't done it before, you log into your Heroku instance by running:
heroku run bash --app my_app