【发布时间】:2014-09-02 16:25:57
【问题描述】:
我正在使用 Rails 4.1 和 PostgreSQL,并且我正在使用 foreigner gem 创建外键约束。但我对fixtures 有一些问题。
当我跑步时:
spring rake test
我收到如下错误:
ActiveRecord::InvalidForeignKey: PG::ForeignKeyViolation: ERROR: update or delete on table "pessoas" violates foreign key constraint "pacientes_pessoa_id_fk" on table "pacientes"
DETAIL: Key (id)=(980190962) is still referenced from table "pacientes".
: DELETE FROM "pessoas"
我找到了解决方法:重新创建数据库:
RAILS_ENV=test spring rake db:reset && spring rake test
当我尝试使用 rake db:fixture:load 使用固定装置为开发数据库播种时出现某种错误。
我已经尝试更改test_helper.rb 中的夹具加载顺序,但这还不够。
有人知道怎么解决吗?我在网上搜索了很多,但没有找到解决方案。
【问题讨论】:
-
这方面有什么进展吗?
-
可以同时运行多个rake脚本
RAILS_ENV=test spring rake db:reset test
标签: ruby-on-rails foreign-keys fixtures minitest foreigner