如何在ActiveRecord中创建外键?我在我的模型中有类似以下的代码:
class Student < ActiveRecord::Base
attr_accessible :name, :level_id
belongs_to :level
end
class Level < ActiveRecord::Base
attr_accessible :number
has_many :students
end
但是schema.rb和开发sqlite3数据库中都没有表明外键约束已经在level_id字段上设置。除了ActiveRecord或Rails之外,我需要手动做些什么吗?我有遗漏什么步骤吗?
使用的Rails版本为3.2.8。