I am using Rails 4.1 and PostgreSQL and I am using the foreigner gem to create foreign key constraints. But I am having some problems with fixtures.
When I run:
spring rake test
I got errors like the following:
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"
I found a workaround: recreating the database:
RAILS_ENV=test spring rake db:reset && spring rake test
I get the some kind of errors when I try to seed the development database with fixtures using rake db:fixture:load
.
I already tried to change the fixture loading order in test_helper.rb
, but it wasn't enough.
Someone know how to fix it? I searched a lot in the web and didn't found a solution.