Unable to run ActiveRecord Migration
I added the gemfile:
gem 'activerecord-reputation-system', require: 'reputation_system'
to my Rails app in order to add upvote/downvote functionity to a model (I'm following Railscast #364). I installed the gem with no problems.
I entered 'rails g reputation_system' and rake db:migrate, but the rake was aborted:
Gem::LoadError: You have already activated rake 12.3.0, but your
Gemfile requires rake 12.0.0. Prepending `bundle exec` to your command
may solve this.
I tried it with 'bundle exec', but the rake was aborted again:
StandardError: An error has occurred, this and all later migrations
canceled:
Directly inheriting from ActiveRecord::Migration is not supported.
Please specify the Rails release the migration was written for:
I updated my gems to see if this was the trouble, but this made no difference.
I can't think of anything else I could do other than finding some way of removing rake 12.3.0 and installing 12.0.0, but this seems illogical.
Any help would be much appreciated, thanks :-)
In Rails 5 migrations require you to specify the Rails version you're using (the migration is specified for) at the top of your migration file, as the error states.
This looks like this:
class CreateYourModels < ActiveRecord::Migration[5.1]
...your migration code
end
Where the bit in brackets is the Rails version you're using.
Then try to run bundle exec rake db:migrate
.
Additional explanation: https://blog.bigbinary.com/2016/03/01/migrations-are-versioned-in-rails-5.html
链接地址: http://www.djcxy.com/p/36000.html上一篇: 在行为中指定标签类型
下一篇: 无法运行ActiveRecord迁移