首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >运行rails db的问题:使用rolify迁移

运行rails db的问题:使用rolify迁移
EN

Stack Overflow用户
提问于 2020-05-11 15:30:34
回答 1查看 66关注 0票数 0

当前正在尝试将rolify安装到我的rails应用程序

按照github上的步骤操作,在运行rails db后得到以下错误:migrate

代码语言:javascript
复制
/home/alex/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rolify-5.2.0/lib/rolify.rb:30: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/home/alex/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.0.3/lib/active_record/associations.rb:1826: warning: The called method `has_and_belongs_to_many' is defined here
rake aborted!
NoMethodError: undefined method `Migration' for ActiveRecord:Module
/mnt/d/linux-docs/projects/code/rails/kream/kream/src/db/migrate/20200511073629_rolify_create_roles.rb:1:in `<main>'

Caused by:
NoMethodError: undefined method `Migration' for ActiveRecord:Module
/mnt/d/linux-docs/projects/code/rails/kream/kream/src/db/migrate/20200511073629_rolify_create_roles.rb:1:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
EN

回答 1

Stack Overflow用户

发布于 2020-05-11 15:58:48

在迁移文件中修改版本号,如下所示

代码语言:javascript
复制
class RolifyCreateRoles < ActiveRecord::Migration[6.0]
  def change
    create_table(:roles) do |t|
      t.string :name
      t.references :resource, :polymorphic => true

      t.timestamps
    end

    create_table(:users_roles, :id => false) do |t|
      t.references :user
      t.references :role
    end

    add_index(:roles, [ :name, :resource_type, :resource_id ])
    add_index(:users_roles, [ :user_id, :role_id ])
  end
end
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61724423

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档