rake db:migrate doesn't work (Rails 4.0.4)

2019-04-28 16:05发布

问题:

I have a new app on Rails 4.0.4 / Ruby 2.1.0. The first thing I did was adding Devise gem. When I want to run rake db:migrate, it just does nothing. No error, but the migration isn't executed.

Could you please help me what to do with this case? I can't find where is the problem.

Thank You! Petr

回答1:

OK, so the problem was that Devise generator generated ".txt" file with migration instead of ".rb" file. Strange, but changing extension solved it.



回答2:

I had the same problem as you Petr and I think I found out why. For some reason when I ran 'rails g devise User', it created a migration (db/migrate/[timestamp]_devise_create_users.rb). That's what it suppose to be, but upon further examination, the migration was missing the '.rb' at the end. So it looked like (db/migrate/[timestamp]_devise_create_users). When I added the .rb at the end, and ran 'rake db:migrate' it worked like a charm. I don't know why rails didn't attach the '.rb' at the end. Hope that helps.



回答3:

After you install devise gem, you have to do the following

  1. rails generate devise:install

The generator will install an initializer which describes ALL Devise's configuration options and you MUST take a look at it. When you are done, you are ready to add Devise to any of your models using the generator

  1. rails generate devise <model>

This is the step that generates the migration. For eg, If you want to add devise to user model, you should do

rails generate devise User

So it will generate a migration to add devise related columns to users table