我正在尝试修改Ruby on Rails应用程序中的数据库迁移。我的数据库使用MySQL,我想向正在创建的表中添加外键。我正在使用以下代码,虽然遵循了在适当列上创建空值的规范,但没有应用外键约束。
class CreateBookCheckOuts < ActiveRecord::Migration
def self.up
create_table :book_check_outs do |t|
t.integer :book_id, :null => false, :options =>
"CONSTRAINT fk_book_check_out_books REFERENCES books(id)"
t.integer :person_id, :null => false, :options =>
"CONSTRAINT fk_book_check_out_people REFERENCES people(id)"
t.datetime :OutDate, :null => false
t.datetime :ReturnDate, :null => true
t.timestamps
end
end
def self.down
drop_table :book_check_outs
end
end