Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database migrations to heroku don't work

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:

  1. Made changes to local code
  2. Ran any migrations LOCALLY - I used bundle exec rake db:migrate
  3. Added all changed files to Git git add -A
  4. Commit all added files to git git commit -m "Adding features"
  5. Pushed the changes to Heroku git push heroku master
  6. 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"
  1. 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.

like image 265
astelvida Avatar asked Nov 09 '22 14:11

astelvida


1 Answers

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

like image 179
Boltz0r Avatar answered Nov 15 '22 06:11

Boltz0r