Ruby on rails “通过关系有很多”;用户“角色”;不存在

Ruby on rails “通过关系有很多”;用户“角色”;不存在,ruby-on-rails,ruby,postgresql,Ruby On Rails,Ruby,Postgresql,你好,我试着通过关系做很多事情,但并不像我期望的那样有效 这是我的模型 def User < ApplicationRecord has_many :user_roles, class_name: "UserRole" has_many :roles, through: :user_roles end def Role < ApplicationRecord has_many :user_roles, class_name: "UserRole" has_many :use

你好,我试着通过关系做很多事情,但并不像我期望的那样有效

这是我的模型

def User < ApplicationRecord
 has_many :user_roles, class_name: "UserRole"
 has_many :roles, through: :user_roles
end

def Role < ApplicationRecord
 has_many :user_roles, class_name: "UserRole"
 has_many :users, through: :user_roles
end

def UserRole < ApplicationRecord
 belongs_to :user
 belongs_to :role
end
我有以下错误
ActiveRecord::StatementInvalid(PG::UndefinedTable:错误:关系“用户角色”不存在)

我被这个错误困扰了2个小时,没有谷歌结果帮我

编辑:

这是我的迁移

class CreateUserRole < ActiveRecord::Migration
  def change
    create_table :user_role do |t|
      t.belongs_to :user, type: :uuid 
      t.belongs_to :role, type: :uuid
    end
  end
end

class CreateUserRole
您是否运行了将
用户角色添加到DB的迁移?是的,我已使用迁移更新了我的原始帖子该表名为
用户角色
。它应该被命名为
user\u roles
,rails会自动识别它。啊,对了!它起作用了,在两小时内看不到这一点感觉太愚蠢了。非常感谢你是我的英雄
class CreateUserRole < ActiveRecord::Migration
  def change
    create_table :user_role do |t|
      t.belongs_to :user, type: :uuid 
      t.belongs_to :role, type: :uuid
    end
  end
end