I am using RubyOnRails 4.1 and PostgreSQL database and I use gem foreigner to create foreign key constraints in the bank. It turns out that this makes some tasks difficult with fixtures .
When I try to run a test:
spring rake test
I often have errors like this:
ActiveRecord::InvalidForeignKey: PG::ForeignKeyViolation: ERROR: update or delete on table "TABELA1" violates foreign key constraint "TABELA2_TABELA1_id_fk" on table "TABELA2"
DETAIL: Key (id)=(980190962) is still referenced from table "TABELA2".
: DELETE FROM "TABELA1"
I can only run my tests because it recreates the database before running them:
RAILS_ENV=test spring rake db:reset && spring rake test
I also can not use rake db:fixture:load
to upar fixtures for the development bank, it gives the same error.
Changing the order of fixtures in the file test_helper.rb
was not enough.
Does anyone know how I can solve this? I did a lot of research on web and did not find a solution.