Reputation:
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.
Upvotes: 4
Views: 1126
Reputation: 781
So, I know for sure this works, though I can't say it's an actual correct work around.
You need to make the user a SUPERUSER.
In my case using Cloud 9, the user I'm logged in as is "ubuntu".
I enter sudo -u postgres psql (actually sudo twice for C9 to access correctly) and type:
ALTER USER ubuntu SUPERUSER;
Quit out and it will work.
If you run tail log/test.rb you can see a PG::InsufficientPrivlege: ERROR when you run your integration test, so the user doesn't have sufficient rights. You would not want to do this in production, but my production is on Heroku so I'm good.
Upvotes: 3