大家好,我在轨道上编写类似Instagram的应用程序,在我安装回形针Gem(5.1(后,我创建了一个必须在数据库中迁移的模型。 正如我在标题中提到的,Rake DB:Migrate 不起作用。 我尝试按照一些解决方案的建议重新启动 Rails 服务器和我的笔记本电脑,还尝试在 ActiveRecord 旁边添加 [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'
并像这样继续下去
当你使用Rails 3时,迁移类不应该有version number
。AFAIK,迁移类的version number
仅在Rails 5.x版本中添加。更改类应该可以修复错误。
class CreatePics < ActiveRecord::Migration
class AddAttachmentImageToPics < ActiveRecord::Migration