25

I cloned my project. Bundled with "bundle install", then run "rake db:migrate". I am getting this error: (when I run the rails server and open my browser to localhost:3000) "Migrations are pending; run 'bin/rake db:migrate RAILS_ENV=development' to resolve this issue."

I checked all migrations one by one and all were executed without errors. Also no errors were shown after the execution of "rake db:migrate".

This is what I see when I execute "rake db:migrate:status"

I am on development environment. Please let me know if you need any other information.

I also tried "bundle exec rake db:migrate", and "bundle exec rake db:migrate:reset" as "burninggramma" suggested.

Any clues what causes the error?

  • 1
    Please show us the output of ```rake db:migrate:status```. Are all migration scripts migrated? – Eich Jan 23 '14 at 13:56
  • You write in the first section: `, then run "rake db:migrate". I am getting this error: `. But you wrote also: `Also no errors were shown after the execution of "rake db:migrate".` So when did those errors come? – p1100i Jan 23 '14 at 13:56
  • @burninggramma oh sorry. When i run the server and open localhost:3000 on my browser –  Jan 23 '14 at 13:57

14 Answers14

33

Interesting. Did you run rake db:create? Assuming you are using sqlite3, do this:

      rm -f db/*.sqlite3
      rake db:create
      RAILS_ENV=development bundle exec rake db:migrate
      rails s -e development

Also, can you list the contents of your config/database.yml file?

Edit: Warning! Obviously, you will lose your existing data.

duhaime
  • 25,611
  • 17
  • 169
  • 224
lewstherin
  • 370
  • 2
  • 9
  • ok, its odd. now it works fine. I think db:create was the key but no clue why this was happening... –  Jan 23 '14 at 14:17
  • 1
    @stefanos-ioannou rake db:create creates the databases if it does not exist. Running migrate without creating the db should throw an error. Not sure what happened here. In retrospect, I would have probably tried rake db:migrate VERSION=0; rake db:migrate to see if there were any errors. – lewstherin Jan 23 '14 at 14:23
17

After running the migrate command, I still had the same error.

What worked for me was to just stop the rails server and start it again.

Jesus H
  • 1,180
  • 3
  • 13
  • 25
6

List your executed migrations with rake db:migrate:status and look if every migration was executed. You can try to cancel your migration with rake db:abort_if_pending_migrations and try to migrate again.

Eich
  • 3,728
  • 1
  • 21
  • 34
  • Check out the status here: https://www.evernote.com/shard/s238/sh/c6b9371c-2fd0-41b8-9d3d-038c2676bb31/a98ae6e0fd5ca6a769eefe2a270f348d –  Jan 23 '14 at 14:11
  • I also used the abort_if_pending and raked again (after dropping everyhting). Still nothing. No error was shown –  Jan 23 '14 at 14:12
4

1. Maybe its default in ruby2/rails4 but have you tried: bundle exec rake db:migrate?

2. Another option would be resetting the whole database - use with CAUTION! resets all the data as well - bundle exec rake db:migrate:reset

+) I would just make sure that you are executing everything in the same development env:

RAILS_ENV=development bundle exec rake db:migrate:reset
RAILS_ENV=development bundle exec rails s
p1100i
  • 3,710
  • 2
  • 29
  • 45
4

Running rake db:migrate RAILS_ENV=test did it for me

brntsllvn
  • 931
  • 11
  • 18
1

I had the same error in the browser, but upon closely looking at the error message, I noticed some how I had an extra white space in the migrate comment and post files. Once I removed it, it worked perfectly.

Parth Shah
  • 56
  • 3
1

Open the database and click schema_migration table. The migrations will be listed as below. enter image description here

Sort the version column and find the latest migration you want to go back. Delete or Insert a new one. Rails keeps all the migration history in this table, so you can adjust the migration history to you liking.

zawhtut
  • 8,335
  • 5
  • 52
  • 76
1

I got the same error working on the Learn Enough to Be Dangerous Rails tutorial. I'm using Git Bash terminals on a Windows 10 machine. The error showed up in the terminal where I'm running guard, after I tried to migrate my db using the command (in another terminal):

$ bundle exec rake db: migrate:

After trying the solution offered by @lewstherin, I still got the same error. I tried the command:

$ rails test And got the explicit and helpful warning:

Migrations are pending. To resolve this issue, run:

bin/rails db:migrate RAILS_ENV=test

I ran the command:

$ bin/rails db:migrate RAILS_ENV=test

and now I'm working again.

jenstreetman
  • 353
  • 3
  • 8
1

For me i just had to migrate for the error:

rake db:migrate --trace

By setting false to config.active_record.migration_error in development.rb might make it workable but i wouldn't recommend it.

Fay007
  • 2,707
  • 3
  • 28
  • 58
0

Here's what worked for me: -gem install rails -v 4.1.0 Inside Gemfile: -gem 'rails', '4.1.0' (replace the newer/older with this) Do bundle install and update -bundle install -bundle update In your application.rb : Remove/Comment - config.active_record.raise_in_transactional_callbacks = true

run bundle rake: -bundle exec rake db:migrate Refresh your page and the error should be gone.

Haider Raza
  • 455
  • 5
  • 8
0

Two reasons 'db:migrate:reset' did not work for me

1) loosing data 
2) we moved from php to rails, so we had an existing DB and the migrations were written on top of it not from the scratch

So What I tried is to update the 'scheema_migrations'(mysql) table with the list of migrations(just version values) that I was really sure were already run on my db(development), this can be lil time consuming process but it works. I would not attempt this on production though.

nowRails
  • 267
  • 2
  • 5
0

I'm guessing the error is that you are creating a table that already exists, I had this problem before. Step 1 look into the error when you rake dv:migrate

Step 2 go to the model where this table is created

Step 3 add drop_table :[YOUR TABLE] right before the create_table :[YOUR TABLE]

Step 2 run rake db:migrate

Step 3 remove the drop_table once the your migration is done

Malek Zalfana
  • 318
  • 2
  • 11
0

I had the same problem in genieacs and this code helped:

rake db:drop rake db:create rake db:schema:load RAILS_ENV=development
rake db:migrate rails s -e development
Pingolin
  • 3,161
  • 6
  • 25
  • 40
-2

You can always run rake db:reset

  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment). - [From Review](/review/low-quality-posts/11199924) – Ryan Gates Feb 09 '16 at 15:17
  • @RyanGates How does this not attempt to provide an answer? It might be completely wrong, [but that doesn't mean we should delete it.](http://meta.stackoverflow.com/q/287563/1849664) Please pay attention when reviewing. – Undo Feb 10 '16 at 01:19
  • @Undo This answer struck me as more of a comment because it sounded like a "try this" kind of comment. I do see what you mean about this being a genuine answer, and thank you for linking me to that post. – Ryan Gates Feb 10 '16 at 14:36