简体   繁体   English

Rails外国人插件

[英]Rails Foreigner Plugin

My user table should have a role_id ( not added in my table yet ) My role table has uses the default primary id: id 我的用户表应具有role_id(尚未在我的表中添加)我的角色表已使用默认的主ID:id

I am currently trying to use the foreigner plugin where it looks like ... 我目前正在尝试在看起来像...的外国人插件中使用...

class AddForeignKeyToUserFromRole < ActiveRecord::Migration
  def change
    add_foreign_key( :users,:roles )
  end
end

But my error is saying the following: Mysql2::Error: Key column 'role_id' doesn't exist in table: ALTER TABLE users ADD CONSTRAINT users_role_id_fk FOREIGN KEY ( role_id ) REFERENCES roles (id) 但是我的错误是在说以下内容:Mysql2 :: Error:表中不存在键列'role_id':ALTER TABLE users添加了CONSTRAINT users_role_id_fk FOREIGN KEY( role_id )参考roles (id)

What is going on?? 到底是怎么回事?? What I'm I missing? 我想念的是什么?

role_id , just like it says, and like you said? role_id ,就像它说的那样,就像你说的那样?

How can you set a foreign key on a table column when the table column doesn't exist? 当表格列不存在时,如何在表格列上设置外键?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM