4
I am using Rubyonrails 4.1 and Postgresql database and use the Gem Foreigner to create foreign key restrictions in the bank. It turns out that this makes some tasks with fixtures.
When I try to run a test:
spring rake test
I usually have mistakes like that:
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 I recreate the bank before I spin them:
RAILS_ENV=test spring rake db:reset && spring rake test
I can’t use it either rake db:fixture:load
to upgrade the fixtures to the development bank, gives the same error.
Change the order of fixtures in the file test_helper.rb
was not enough.
Does anyone know how I can fix this? I did a lot of research on web and I couldn’t find a solution.
I have no knowledge of Rails, but might that help you (Foreign key support)? http://edgeguides.rubyonrails.org/4_2_release_notes.html
– gmsantos
@gmsantos Interesting... The version
4.2
(still in Beta) will support Foreign Keys natively (today I use a Gem). But the link says nothing about fixtures and testing, we may no longer have this problem in the future. I will research more on... Thanks! = ) (I would still like a solution for the version4.1
)– user7261