我有 2 个模型,员工和用户具有 has_one,belongs_to 关系。用户表有一个“登录”列,它只需是雇员表中的“emp_id”值。我试图通过以下迁移来捕捉这种关系:
class AddFkToUsers < ActiveRecord::Migration
def change
add_foreign_key( :users, :employees, :source_column => :login, :foreign_column
=> :emp_id )
end
end
但是当我尝试运行此迁移时,我收到一条错误消息:
Mysql2::Error: Key column 'employee_id' doesn't exist in table: ALTER TABLE `users`
ADD CONSTRAINT `users_employee_id_fk` FOREIGN KEY (`employee_id`) REFERENCES
`employees`(id)/home/vasu/.rvm/gems/ruby-1.8.7-p371/gems/activerecord-
3.2.9/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:245:in `query'
我以为我也可以指定外国列名,这不可能吗?