rails:回形针gem的迁移问题

dffbzjpn  于 2021-09-29  发布在  Java
关注(0)|答案(1)|浏览(456)

我正在尝试迁移rails应用程序,但失败了。回形针宝石迁移中的问题。
我尝试使用两种方法进行迁移,但两种方法都不能正常工作:

  1. class AddAttachmentImageToItems < ActiveRecord::Migration[6.1]
  2. def self.up
  3. add_attachment :items, :image
  4. end
  5. def self.down
  6. remove_attachment :items, :image
  7. end
  8. end

还尝试:

  1. class AddAttachmentImageToItems < ActiveRecord::Migration[6.1]
  2. def change
  3. add_attachment :items, :image
  4. end
  5. end

赛后 rails db:migrate 显示错误:

  1. /Users/zi/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/pry-byebug-3.8.0/lib/pry-byebug/control_d_handler.rb:5: warning: control_d_handler's arity of 2 parameters was deprecated (eval_string, pry_instance). Now it gets passed just 1 parameter (pry_instance)
  2. == 20210713231704 AddAttachmentImageToItems: migrating ========================
  3. -- add_attachment(:items, :image)
  4. rails aborted!
  5. StandardError: An error has occurred, this and all later migrations canceled:
  6. wrong number of arguments (given 4, expected 3)
  7. /Users/zi/rails/stage_1/db/migrate/20210713231704_add_attachment_image_to_items.rb:3:in `up'
  8. /Users/zi/rails/stage_1/bin/rails:5:in `<top (required)>'
  9. /Users/zi/rails/stage_1/bin/spring:10:in `block in <top (required)>'
  10. /Users/zi/rails/stage_1/bin/spring:7:in `<top (required)>'
  11. Caused by:
  12. ArgumentError: wrong number of arguments (given 4, expected 3)
  13. /Users/zi/rails/stage_1/db/migrate/20210713231704_add_attachment_image_to_items.rb:3:in `up'
  14. /Users/zi/rails/stage_1/bin/rails:5:in `<top (required)>'
  15. /Users/zi/rails/stage_1/bin/spring:10:in `block in <top (required)>'
  16. /Users/zi/rails/stage_1/bin/spring:7:in `<top (required)>'
  17. Tasks: TOP => db:migrate
  18. (See full trace by running task with --trace)
rnmwe5a2

rnmwe5a21#

在ruby版本中发现问题,降级到2.6.8,迁移工作正常。

相关问题