Rake DB无法使用Paperclip(ruby 2.4.0p0和Rails 5.1.0)

时间:2017-05-11 01:19:18

标签: ruby-on-rails ruby ruby-on-rails-5

我正在使用Paperclip创建一个Pinterest克隆,我正在尝试搜索我的迁移文件,但是我收到了一个错误:

我能够运行generate cmd:

pinterested-app git:(master) ✗ rails generate paperclip user image
Running via Spring preloader in process 88926
      create  db/migrate/20170511010912_add_attachment_image_to_users.rb

但是当我跑去试图耙db时,我得到了以下内容:

➜  pinterested-app git:(master) ✗ rake db:migrate
rake aborted!
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:

  class AddAttachmentImageToUsers < ActiveRecord::Migration[4.2]
/Users/rthomas/.rvm/gems/ruby-2.4.0/gems/activerecord-5.1.0/lib/active_record/migration.rb:525:in `inherited'
/Users/rthomas/Dropbox/rails-dev/pinterested-app/db/migrate/20170511010912_add_attachment_image_to_users.rb:1:in `<top (required)>'
/Users/rthomas/.rvm/gems/ruby-2.4.0/gems/activesupport-5.1.0/lib/active_support/dependencies.rb:292:in `require'
/Users/rthomas/.rvm/gems/ruby-2.4.0/gems/activesupport-5.1.0/lib/active_support/dependencies.rb:292:in `block in require'
/Users/rthomas/.rvm/gems/ruby-2.4.0/gems/activesupport-5.1.0/lib/active_support/dependencies.rb:258:in `load_dependency'
/Users/rthomas/.rvm/gems/ruby-2.4.0/gems/activesupport-5.1.0/lib/active_support/dependencies.rb:292:in `require'
/Users/rthomas/.rvm/gems/ruby-2.4.0/gems/activerecord-5.1.0/lib/active_record/migration.rb:962:in `load_migration'
/Users/rthomas/.rvm/gems/ruby-2.4.0/gems/activerecord-5.1.0/lib/active_record/migration.rb:958:in `migration'
/Users/rthomas/.rvm/gems/ruby-2.4.0/gems/activerecord-5.1.0/lib/active_record/migration.rb:953:in `disable_ddl_transaction'
/Users/rthomas/.rvm/gems/ruby-2.4.0/gems/activerecord-5.1.0/lib/active_record/migration.rb:1305:in `use_transaction?'
/Users/rthomas/.rvm/gems/ruby-2.4.0/gems/activerecord-5.1.0/lib/active_record/migration.rb:1297:in `ddl_transaction'
/Users/rthomas/.rvm/gems/ruby-2.4.0/gems/activerecord-5.1.0/lib/active_record/migration.rb:1229:in `execute_migration_in_transaction'
/Users/rthomas/.rvm/gems/ruby-2.4.0/gems/activerecord-5.1.0/lib/active_record/migration.rb:1201:in `block in migrate_without_lock'
/Users/rthomas/.rvm/gems/ruby-2.4.0/gems/activerecord-5.1.0/lib/active_record/migration.rb:1200:in `each'
/Users/rthomas/.rvm/gems/ruby-2.4.0/gems/activerecord-5.1.0/lib/active_record/migration.rb:1200:in `migrate_without_lock'
/Users/rthomas/.rvm/gems/ruby-2.4.0/gems/activerecord-5.1.0/lib/active_record/migration.rb:1150:in `migrate'
/Users/rthomas/.rvm/gems/ruby-2.4.0/gems/activerecord-5.1.0/lib/active_record/migration.rb:1007:in `up'
/Users/rthomas/.rvm/gems/ruby-2.4.0/gems/activerecord-5.1.0/lib/active_record/migration.rb:985:in `migrate'
/Users/rthomas/.rvm/gems/ruby-2.4.0/gems/activerecord-5.1.0/lib/active_record/tasks/database_tasks.rb:171:in `migrate'
/Users/rthomas/.rvm/gems/ruby-2.4.0/gems/activerecord-5.1.0/lib/active_record/railties/databases.rake:58:in `block (2 levels) in <top (required)>'
/Users/rthomas/.rvm/gems/ruby-2.4.0@global/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'

1 个答案:

答案 0 :(得分:4)

由于Rails要求指定Rails版本并且您正在使用rails 5.1,请尝试在迁移文件中的ActiveRecord :: Migration末尾添加[5.1]:

class AddAttachmentImageToUsers < ActiveRecord::Migration[5.1]

然后再试一次。