Ruby on rails 3 Rails:对“的外键约束”;测试“;数据库使用MySQL

Ruby on rails 3 Rails:对“的外键约束”;测试“;数据库使用MySQL,ruby-on-rails-3,activerecord,foreigner,Ruby On Rails 3,Activerecord,Foreigner,我正在尝试使用启用Rails中的外键约束。它正在我的开发数据库上工作,但当我尝试运行测试时,出现以下错误: Errors running test:units! #<ActiveRecord::StatementInvalid: Mysql2::Error: Can't create table 'arizona_test.#sql-368_be' (errno: 150): ALTER TABLE `arizona_downloads` ADD CONSTRAINT `arizona

我正在尝试使用启用Rails中的外键约束。它正在我的开发数据库上工作,但当我尝试运行测试时,出现以下错误:

Errors running test:units! #<ActiveRecord::StatementInvalid: Mysql2::Error: Can't create table 
'arizona_test.#sql-368_be' (errno: 150): ALTER TABLE `arizona_downloads` ADD CONSTRAINT 
`arizona_downloads_ibfk_1` FOREIGN KEY (`books_id`) REFERENCES `books`(id) ON DELETE SET NULL>

运行测试时出错:单位# 仔细看,我看到这是一个MySQL错误150。运行
显示引擎INNODB状态
显示:

120808 11:24:29 Error in foreign key constraint of table arizona_test/#sql-368_6e:
 FOREIGN KEY (`book_id`) REFERENCES `books`(id) ON DELETE SET NULL:
Cannot find an index in the referenced table where the
referenced columns appear as the first columns, or column types
in the table and the referenced table do not match for constraint.
这是因为我的开发环境使用bigint(20)作为id,而schema.rb使用int(11),这是因为迁移依赖于Rails的默认id大小

为了解决这个问题,我更改了,并重新进行了迁移