I am trying to create an ActiveRecord Object.But I'm getting this error while creating it.
(0.1ms) ROLLBACK
ActiveRecord::StatementInvalid: PG::InFailedSqlTransaction: ERROR: current transaction is aborted, commands ignored until end of transaction block
Any ideas folks regarding the issue.
In my case, I received this error simply because I had not rake'd my test db.
I got that problem. And I found out that it was my query. It mean when I query with association without specifying a table column. ex:
In Holiday model I query
The error occurs because I didn't specify which table's
id
It worked for me after I changed the code toI had this issue. Just restart the Rails Server and it should work
you can see what really going on in postgresql log, I spend a lot of time to dig into this issue, and finally find out that we misuse upsert gem cause a PG error, only in postgresql log have the real info of what's going on
https://github.com/seamusabshere/upsert/issues/39
None of the other answers fix the root cause of the issue.
The problem is that when Postgres raises an exception, it poisons future transactions on the same connection.
The fix is to rollback the offending transaction:
See reference.
This issue was occurring in my test environment, and was caused by the fact that each test was wrapped in its own transaction.
I was using the database_cleaner gem, and have it configured so as NOT to wrap tests in a transaction if they use javascript. So to solve the issue, I added
js: true
to each spec that was causing this problem. (Even thought the specs did not actually use javascript, this was the most convenient way to ensure that the tests would not be wrapped in a transaction. I am sure there are less hack-ish ways of doing so, though).For reference, here is the database_cleaner config from
spec/support/database_cleaner.rb
:If you are not using database_cleaner, then probably the reason the tests would be wrapped in transactions would be that the
use_transactional_fixtures
option is set totrue
inspec/spec_helper.rb
. Try setting it to false.