Trouble deploying to Heroku -- logs included - ruby-on-rails

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

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.)

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

Check db status through DATABASE_URL

I've been given access to Heroku application with rather strange setup. It has one database but when I run heroku config, I get different DATABASE_URL and HEROKU_POSTGRESQL_BRONZE_URL.
When I run heroku pg:info I get the following result:
=== HEROKU_POSTGRESQL_BRONZE_URL
Plan: Dev
Status: available
Connections: 1
PG Version: 9.2.4
Created: 2013-09-05 11:02 UTC
Data Size: 6.5 MB
Tables: 0
Rows: 0/10000 (In compliance)
Fork/Follow: Unsupported
I realised that my database is at DATABASE_URL, but I can't access that database, only through heroku run console. All heroku pg commands fail with this message:
! Unknown database: DATABASE_URL. Valid options are: HEROKU_POSTGRESQL_BRONZE_URL
If I run heroku pg HEROKU_POSTGRESQL_BRONZE_URL, I get access to empty database from above.
Since I have some issues with running migrations, I think my database might be full, and I'd like to check it. Any ideas how I can do that?
Here's the error after I run heroku run rake db:migrate:
PG::Error: ERROR: permission denied for relation schema_migrations
: INSERT INTO "schema_migrations" ("version") VALUES ('20130918114202')
More information about the setup:
rails 3.2.12
RAILS_ENV: staging (I don't have access to production, but I know this is "dev" server and there's also real "staging" from which this app was forked).
I have same problem and i fixed it:
Just Keep a Backup from your database and restore it back again, here is the steps:
heroku pg:info <-- to get the Database Name
heroku addons:add pgbackups <-- make sure you have the addons for backup
heroku pgbackups:capture <-- Capture the backup
heroku pgbackups <-- check your backups and make sure its there
heroku pg:reset DATABASE_NAME <-- Reset your database don't worry we have a backup, replace DATABASE_NAME with database name
heroku pgbackups:restore DATABASE_NAME b001 <-- Restore the backup again, replace DATABASE_NAME with database name and b001 with your Database version you can see this version number in heroku pgbackups step
heroku run rake db:migrate <-- Now you can run your migration and Operate in normal mode.
This seems like something screwy on the Heroku side. Have you tried submitting a ticket with them? I've always had good luck with their support.
I just got an update from my client. Before, I couldn't drop the database, because of the data in it. At the end, we decided to drop the database since the data can be added back (it's dev server, doesn't matter if we loose some dummy data).
I didn't find a solution for the problem above, but promoting HEROKU_POSTGRESQL_BRONZE_URL and restoring from backup solved the issue about not being able to access the database.

app works on Heroku, but server error accessing DB through console

I have a Rails app on Heroku that works fine when I access it through a browser. It's also displaying data from the database correctly. However, when I try to update the database through the console, I'm getting an internal server error message. The model's name is Total.rb (table's name is "totals") I'm doing this to get the first entry
t = Total.first
! Internal server error
Since the app's working through the browser, I'm not sure if this is a problem I'm causing or if it's heroku's fault. It's been a while since I updated through the console, so I'm not sure if I'm doing it right, but that seems pretty straightforward.
I had always accessed the console with 'heroku console' now it's telling me to use 'heroku run console' but when I did that, it told me that the heroku gem has been deprecated and I need to install the Toolbelt. I installed the Toolbelt, authenticated, and tried to run a console session but same result.
Here's my Heroku info
Addons: heroku-postgresql:dev
pgbackups:plus
zerigo_dns:basic
Dynos: 1
Git URL: git#heroku.com:blahblah
Owner Email: blahblah#gmail.com
Repo Size: 19M
Slug Size: 4M
Stack: bamboo-mri-1.9.2
Web URL: http://blahblah.com
Workers: 0
Update
If I try to run the console after installing the Heroku toolbelt, I get
heroku run console
Running `console` attached to terminal... up, run.3213
bash: console: command not found
I was having the same problem there is some internal issue going on with the heroku CLI client that I don't understand.
The solution posted in this stackoverflow thread solved it for me:
Here is the link
Could Total be a reserved word? You could try renaming the table or creating a temp one, then testing the same query with that. If nothing else it will eliminate one possible problem area.

Rails/Heroku : db:push runs correctly but does not create the DB

I've been having problems yesterday with Heroku shared Postgres DB. It looks like my db is not correctly 'pushed' to my heroku DB.
Configuration
Using 'pg' gem for both development and production environments.
Using Heroku's 'shared-database' add-on.
Running Rails 3.1.1.
What I'm trying to do
Push my source code to Heroku and then synchronize my postgres DB with Heroku's one. No problem for the source itself, but I can't get my DB up and running.
What I've tried so far
1: Source code push : git push heroku master. OK. This works.
2: Then I try to run : heroku db:push. Seems to be running normally, no error, the schema is sent to Heroku, the different tables are correctly detected and seem to be sent as well :
3: Let's check it out, is everything allright ? heroku info :
Doh ! The database is still empty (and therefore I get DB-related errors when accessing dynamic pages). Can't understand what's happening, I've spent time on this issue yesterday evening but only been mpessing with Heroku for a little while and never encountered this issue. Any clues ?
I'm not convinced that the Database size figure is a live figure. Here's a clean deployment of an app to Heroku and the output of heroku info at each stage. The first run is post application creation, the second after a push of the code, the third after a heroku db:push.
The database was uploaded before the third output and the application is running however the DB:size is not reporting the figure.
Is your application actually erroring because the database isn't present?
The problem is in the commit process.
You should run manually after each commit from your console :
heroku run rake db:migrate
Enjoy
daniel

Resources