我正在使用 Rails 4.1 和 PostgreSQL,并且正在使用foreigner gem来创建外键约束。但是我在固定装置方面遇到了一些问题。
当我运行时:
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
,但这还不够。
有人知道如何解决吗?我在网上搜索了很多并没有找到解决方案。