I am currently making my way through the Ruby on Rails tutorial over at http://ruby.railstutorial.org/ and I am trying to migrate the demo_app database to heroku.
heroku rake db:migrate
rake aborted!
unable to open database file
I have read on other stackoverflow posts that some people fixed this by entering
group :production, :staging do
gem "pg"
end
group :development, :test do
gem "sqlite3-ruby", "~> 1.3.0", :require => "sqlite3"
end
in the gemfile. I also entered it into my gemfile and then deleted my old gemfile.lock and redid my bundle install AND rake db:migrate command. I am still receiving the same error.
I am obviously brand new to ruby, rails and heroku but I understand that the problem seems to be that I am using sqlite locally and postgresql in production (on heroku). Do I now have to install this postgresql onto my machine and then RE-migrate the DB? I am afraid I will not be able to get much more out of the tutorials (or ruby on rails itself) if I cannot use heroku.
Kill it!
I was having the same problem and found no solutions. I think something we are doing in those tutorials is leading us to mangle the database.yml file that heroku generates.
I ended up destroying my heroku app
heroku destroy
and then creating a new one, pushing a fresh copy, and running
heroku create
git push heroku master
heroku rakedb:migrate
This time everything worked fine! Just make sure you have the pg gem in your gemfile for production
group :production do
gem "pg"
end
and add config/database.yml to your .gitignore file too for good measure.
or if it's working ok locally do a heroku db:push to magically put your local sqlite DB into Heroku's postgresql db.
I always work with the same DB platform locally just so I don't run into any differences (usually only when you start doing DB specific SQL) so I run Postgresql locally too.
Had the same problem... with Heroku interface... ran:
heroku rake db:migrate --trace
and found the problem to be with faker, not being found...Since 'faker' in our Gemfile is loaded in the development group, I loaded it in the production group as well.
saved Gemfile
bundle install
git add .
git commit -m "fixed faker"
git push
git heroku push
heroku rake db:migrate
heroku rake db:populate
now everything works...the QUESTION, now is what to do with 100 users on my production site?
At least I can continue with Hartl's tutorial!!
Related
I've been trying to migrate my database to heroku, without success. I have added a few more users to my database and when trying to log them in with email address and password on my heroku app, I get invalid email/password error, even though this works perfectly fine on my local server. NO errors at all when doing all the steps described below.
As suggested in a previous post, I've tried the following:
Made changes to local code
Ran any migrations LOCALLY - I used bundle exec rake db:migrate
Added all changed files to Git git add -A
Commit all added files to git git commit -m "Adding features"
Pushed the changes to Heroku git push heroku master
Ran heroku run rake db:migrate
After I run this I get:
astelvida:~/workspace/sample_app (master) $ heroku run rake db:migrate
Running rake db:migrate on ⬢ shrouded-ravine-80000... up, run.2794
ActiveRecord::SchemaMigration Load (0.8ms)
SELECT "schema_migrations".* FROM "schema_migrations"
Following migrations do heroku restart
I've also checked my .sqlite3 file to check that the new users actually exist in the database.
I've also tried this: $ bundle exec rake db:migrate RAILS_ENV=production
I've also updated my gemfile.lock.
My gems in dev & production:
group :development, :test do
gem 'sqlite3', '1.3.9'
gem 'byebug', '3.4.0'
gem 'web-console', '2.0.0.beta3'
gem 'spring', '1.1.3'
end
group :production do
gem 'pg', '0.17.1'
gem 'rails_12factor', '0.0.2'
gem 'puma', '3.1.0'
end
Note: I run bundle install --without production, however this is how I've always been using it, and the login data works for some of the users i've created in the past. Also I'm using rails 4.2.2.
Ok... let's get something clear here.
Rake db:migrate doesn't migrate the data of the database. It runs all migrations (Table creations, updates, etc) so that the database structure is the same, however the data isn't! It's a fresh new database with the same structure.
What you're doing is making sure your PG database has the same structure as your sqlite3 database and it does. But if you want to pass the data from one to another It's gonna be hard i would say. You have to create a dump file from your sqlite 3 database, change it to pg and run in your heroku app.
Here is a question about it.
Convert SQLITE SQL dump file to POSTGRESQL
I seem to have reached a bump, searched here and on other foruns but nothing. I'm running rails 3.2.3 and ruby 1.9.3 and want to deploy my app on heroku.
I've created the cedar and although I can git push heroku master I am getting a complete 500 server error.
I suspect is it because my DB isn't there. However, I can't seem to get it there.
I've run:
heroku run rake db:create -> This gives out some warnings about deprecation and then dkhgclqccm already exists
So it exists already? So lets migrate it:
heroku run rake db:migrate
However this outputs:
<deprecation errors>
rake aborted!
An error has occurred, this and all later migrations canceled:
PG::Error: ERROR: relation "hphotos" does not exist
: ALTER TABLE "hphotos" ADD COLUMN "description" character varying(255)
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
That particular migration is:
class AddDescriptionToHphotos < ActiveRecord::Migration
def change
add_column :hphotos, :description, :string
end
end
It seems good to me, don't know why its giving me this error :/
One Last thing, even if this migrations worked, my DB would be empty and me seeds.rb doesn't have all the necessary data for the database. So I though about pushing the hole DB.
heroku db:push
! Taps Load Error: cannot load such file -- sqlite3
! You may need to install or update the taps gem to use db commands.
! On most systems this will be:
!
! sudo gem install taps
Why is this showing?
I installed the 'heroku' gem and the 'taps' gem and I got this in my gem file:
group :development, :test do
gem 'mysql2'
end
group :production do
gem 'pg'
end
Also, when I run heroku run rake db:version, it shows: Current version: 20120508130957
This is actually 5 migrations short on my currrent version, but I can't migrate it as shows the error I spoke of above...
Thanks in advance
Heroku comes with a database set up (which is why db:create didn't work). have you tried heroku run rake db:schema:load? This should take your schema.rb file and load it up into the DB. This is a much better way of doing it than db:migrate every time you want to setup a new DB
Edit:
For your last question about taps, it looks like it's trying to use sqlite locally but you only have pg in your Gemfile. You probably have in config/database.yml adapter: sqlite. So either you need to use postgres locally and change that adapter to postgres, or go the easier route and use sqlite locally and add that to the :development group.
Note that heroku only uses postgres so I would not suggest developing off of mysql since there are some inconsistencies in some syntax and how you do a couple of things between the two platforms. Then again, if you're using only ANSI-compatible queries or just using rails' methods to activate queries then you should be ok either way.
I think you need to check your migrations closely to see if you actually have a file which says:
def up
create_table :hphotos do |t|
[...]
end
It seems that the table hasn't been created remotely and you are attempting to modify it.
The solution is to add not only taps gem but also sqlite3 gem into the Gemfile, into the :development group. If you are using sqlite3 in your development, then adding taps gem would be enough.
But since you are using mysql2 on your development so to solve that problem you have to add both.
group :development do
gem 'taps'
gem 'sqlite3'
end
im having this issue when i try to deploy my ruby on rails application to heroku, i check different posts here, because i saw this issue before but i couldnt fix it.
when i try to run:
$ heroku rake db:migrate
I get a lot of these ones: DEPRECATION WARNING:
and then:
rake aborted!
Please install the postgresql adapter: `gem install activerecord-postgresql-adapter` (pg is not part of the bundle. Add it to Gemfile.)
Tasks: TOP => db:migrate => db:load_config
(See full trace by running task with --trace)
I tried to change my Gemfile with 'pg' and my group :assets do to :production, i know im missing something but i could'nt figured out what.
Some ideas?
Also when I go to the app url, I get this:
Application Error
An error occurred in the application and your page could not be served. Please try again in a few moments.
If you are the application owner, check your logs for details.
Thanks in advance for any suggest and help!!!
You have to use Postgres on Heroku, you can't use sqlite3 because Heroku prohibits you from saving to the file system. So add the pg gem to your production bundle and re-deploy then your migrations should run.
Answer here is simple, add the following production in your gemfile as:
group :production do
gem 'pg'
end
Your local machine won't work with this production, so we now have to bundle it by ignoring PostgreSQL gem which can be done as:
bundle install --without production
After this, try heroku rake db:migrate. Must work.
Good luck
I reading Rails Tutorial and created a Sample_App.
My code is available here: https://github.com/namic/sample_app
Heroku is running the app here: http://afternoon-mist-7865.herokuapp.com/
It works in test, development and production environment on my laptop, but Heroku denies me the joy with "We're sorry, but something went wrong."
Any suggestions?
Solution:
Add to Gemfile:
group :production do
gem 'pg'
end
And remember to run bundle install without production, if you dont want postgresql local:
bundle install --without production
Check the logs and make sure you ran the migrations on heroku.
heroku run rake db:migrate
I've got a basic app that I'm trying to deploy to Heroku. I can push it to Heroku with git and it shows the default Rails welcome page, but when I try to access any subpages, (pages that work when I deploy on a local server with rails server) I get "something went wrong" messages.
I pulled up the log and I'm get 500 responses from the server and lots of ActiveRecord::ConnectionNotEstablished messages which seems to be an issue connecting to the database.
Further, when I tried to run heroku rake db:migrate, I get the following errors
rake aborted!
Please install the postgresql adapter: `gem install activerecord-postgresql-adap
ter` (pg is not part of the bundle. Add it to Gemfile.)
Tasks: TOP => db:migrate => db:load_config
(See full trace by running task with --trace)
Per the suggestion above, I did add gem 'pg' to the Gemfile After running gem install pg and then bundle install. Also, I tried gem install activerecord-postgresql-adapter (on Windows) and get
ERROR: Could not find a valid gem 'activerecord-postgresql-adapter' (>= 0) in a
ny repository
ERROR: Possible alternatives: activerecord-jdbcpostgresql-adapter, activerecord
-postgis-adapter, activerecord-jdbcmssql-adapter, activerecord-jdbcmysql-adapter
, activerecord-postgresql-cursors
From the suggestion of the book that I'm reading, I ran heroku db:push and it competed without error, but it didn't solve the problem of the pages not rendering once the app is push to Heroku.
update: I've tried installing the activerecord-jdbcpostgresql-adapter as suggested as a possible alternative. I updated the Gemfile with
group :production, :staging do
gem 'pg'
end
and the database.yml file with
production:
adapter: jdbcpostgresql
and when I heroku rake db:migrate, it still gives me the message telling me to install postgresql adapter
If heroku rake db:migrate runs without error, then your database connection info is correct. It's likely that there's another error preventing the page from rendering correctly. If you tail your heroku logs while making a request, are you still getting the same database error? I suspect that you'll find it's a different error that you'll need to fix.