Heroku incorrectly reports a model validation error? - ruby-on-rails

I'm a newbie developing a rails app. I pushed the master to Heroku and ran "git heroku run rake db:migrate" without problems.
The app runs great locally, but on Heroku a "duration" field in one of my tables erroneously reports an error indicating that it "can not be blank" even though I pass it a valid value per the model's validation. This behavior only occurs on Heroku. Locally, the "presence" validation behaves as expected. Heroku does not indicate any problen with my database schema, but it appears something may be wrong in the database. That's my hunch, but I don't know.
To troubleshoot: I reset the Heroku database by running "heroku pg:reset DATABASE" and then ran "heruko run rake db:migrate". Those commands did not solve the problem.
I don't know how to troubleshoot further. Any thoughts, suggestions or ideas? I'm running SQLite3 in my development & testing environments with pg on Heroku. I haven't made any unusual SQLite migrations. I do plan to get rid of SQLite3 and go with pg entirely, but I need to solve this problem first. Thanks in advance for any help!

Related

Error when creating database record on rails console

I'm trying to create a new record through the rails console but I'm getting the following error:
PG::ConnectionBad: FATAL: database "my_database_development" does not exist
I've recently changed from Sqlite3 to PG to be able to deploy to Heroku. Is this what is giving the error?
Thanks a lot!
It looks like you have not yet run
rake db:create
This will "create" the databases on your PostgreSQL server. A step that you didn't have to do with SQLite, but Postgres requires it. As TK-421 said, make sure that your database.yml is configured for your OS and Postgres, not SQLite.
Here is a (possibly outdated) Railscast on the topic.
http://railscasts.com/episodes/342-migrating-to-postgresql
Is this running locally, or on Heroku? In config/database.yml, the local user you specify will need to have CREATEDB privileges (as a superuser, for example).
There's a little more configuration required in this case than for SQLite. Google will show you a bunch of tutorials specific to your OS.
If you see this problem in production on heroku, start the console like this:
rails console production
If you have that problem in development on your machine, check your config/database.yml. It is points to a local development database that does not exist.

Demo app on heroku gives Application Error

I am following Michael Hartl's Rails Tutorials screen cast series and having trouble in deploying demo Rails application in Heroku. The deploy is successful but when I try to open the URl, it gives an Application Error
The link for the app is http://evening-lake-3818.herokuapp.com/ . Please Help !!
Looks like you've not used rake db:migrate
Heroku
This error is a heroku error (not a rails problem) - the typical Rails errors are the red error page, which says something like "Something went wrong" or "Page Cannot Be Found":
The error you are seeing is a Heroku problem, and is typically because you've either not set up your production database, or you have not got the required migrations to make it work.
The way to fix this is to run:
# heroku run rake db:migrate
Other than that, you'll also need to ensure you have the config/database.yml set up correctly for your production environment (which I can help you with if you need it)

Fetch database from production to development

I love very much heroku database pulling:
heroku db:pull
It is very helpful when you are fixing bugs caused by data at production.
Is it any gems that can easily pull database from production without heroku?
Check out the Tap gem: https://github.com/ricardochimal/taps. This should do what you want.

How to fix a problematic earlier migration in Rails?

I wrote a Rails app locally and have maybe 10-15 migrations written. This all works fine locally.
When I wanted to deploy on heroku, I ran into a problem because they are using a earlier version of PostGreSQL than what I was using locally. One of my earliest migrations is failing because of a missing DB function in one of my database views.
I found out a way to hack around the DB function issue, but now I'm stuck because I can't write a new migration that changes the view to use the hack, since the rake db:migrate will abort after it hits the original problematic view creation.
What can I do to solve this?
First of all drop your db:
heroku pg:reset
Then run your new migrations:
heroku rake db:migrate

Rails 3 db:reset and assets

I made what I now see as a mistake (better now than later, not as good as never) of running rake db:reset on my local dev env to try to solve a problem I was having with assets production compilation(RAILS_ENV=production bundle exec rake assets:precompile) referring to a PG ERROR summarized bellow.
PGError: ERROR: relation "schools" does not exist
LINE 4: WHERE a.attrelid = '"schools"'::regclass
The tables get created properly and seeding works with exception of active_admin. I use Active_Admin that did not seed properly. My emails mysteriously stopped being sent and the assets compilation for production still fails with the same error. I am not sure what I can post here to help you understand the issue but if someone could help me tackle one at a time that would be much appreciated. Here are my issues in list form.
active_admin not seeding (I tried running: rails generate active_admin:install but that started to break things further so I reverted this.
PG ERROR on assets precompile for production persists.
Email stopped being processed (not using DJ)
Env.
Rails 3.1
------UPDATE 00------
2 is Solved. db:reset dropped all my tables but only migrated and seeded my development database so I also had to:
run migrate and seed for production ( rake db:migrate RAILS_ENV="production", rake db:seed RAILS_ENV="production")
before compiling production assets(rake db:migrate RAILS_ENV="production")
I ended up splitting this question into 2 parts. The second part got better contribution and is where I found the solution for this as well.
Detailed solution here

Resources