rake db:migrate在安装paperclip gem后不起作用

时间:2017-07-20 12:08:44

标签: ruby-on-rails ruby rails-activerecord

大家好我即时编写了一个类似Instagram的应用程序,在安装了paperclip gem(5.1)后,我创建了一个必须在db中迁移的模型。正如我在标题中提到的rake db:migrate不起作用。我尝试按照一些解决方案的建议重新启动rails服务器和我的笔记本电脑,也尝试像其他人建议的那样在ActiveRecord :: Migration旁边添加[5.1]。

class CreatePics < ActiveRecord::Migration[5.1]

更改某些版本后仍然无法正常工作。 如果它有用,代码项目就在这里https://github.com/leobouts/Instagramm

我得到的错误是

rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute 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 AddAttachmentImageToPics < ActiveRecord::Migration[4.2]
/Users/leonidas/.rvm/gems/ruby-2.4.0/gems/activerecord-5.1.2/lib/active_record/migration.rb:525:in `inherited'
/Users/leonidas/Desktop/Instagramm/db/migrate/20170719181859_add_attachment_image_to_pics.rb:1:in `<top (required)>'
/Users/leonidas/.rvm/gems/ruby-2.4.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:292:in `require'

继续这样下去

1 个答案:

答案 0 :(得分:0)

当您使用 Rails 3 时,迁移类不应拥有version number。 AFAIK,迁移类的version number仅在 Rails 5.x 版本中添加。更改类应该可以解决错误。

class CreatePics < ActiveRecord::Migration

class AddAttachmentImageToPics < ActiveRecord::Migration