Question

My user table should have a role_id ( not added in my table yet ) My role table has uses the default primary 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)

What is going on?? What I'm I missing?

Was it helpful?

Solution

role_id, just like it says, and like you said?

How can you set a foreign key on a table column when the table column doesn't exist?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top