ActiveRecord::StatementInvalid: PG InFailedSqlTransaction

后端 未结 10 2070
礼貌的吻别
礼貌的吻别 2020-12-13 01:33

I am trying to create an ActiveRecord Object.But I\'m getting this error while creating it.

(0.1ms)  ROLLBACK
ActiveRecord::StatementInvalid: PG::InFailedSql         


        
相关标签:
10条回答
  • 2020-12-13 01:57

    Problem:

    1. The program executes incorrect SQL statement. Incorrect SQL statement is root cause of the problem.
    2. The program does not ROLLBACK or RELEASE SAVEPOINT immediately after incorrect SQL statement.
    3. The program executes SQL statements after incorrect SQL statement.
    4. PostgreSQL raises ERROR: Current transaction is aborted, commands ignored until end of transaction block

    Solution:

    Find incorrect SQL statement and correct it. If you don't want to correct the SQL statement, use ROLLBACK or RELEASE SAVEPOINT after incorrect SQL statement.

    0 讨论(0)
  • 2020-12-13 01:59

    In my case the Postgres configuration at /usr/local/var/postgres/postgresql.conf had the datetype as the international format of dmy

    Changing datetype to the American format of mdy fixed this issue for me.

    0 讨论(0)
  • 2020-12-13 02:02

    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

    0 讨论(0)
  • 2020-12-13 02:05

    I had this issue. Just restart the Rails Server and it should work

    0 讨论(0)
  • 2020-12-13 02:08

    I've run into this error when referencing a column in my specs that no longer exists. Make sure your database is up to date and your code doesn't expect a column that doesn't exist.

    0 讨论(0)
  • 2020-12-13 02:12

    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:

    RSpec.configure do |config|
    
      config.before(:suite) do
        DatabaseCleaner.clean_with :deletion
      end
    
      config.before(:each) do
        DatabaseCleaner.strategy = :transaction
      end
    
      config.before(:each, :js => true) do
        DatabaseCleaner.strategy = :deletion
      end
    
      config.before(:each) do
        DatabaseCleaner.start
      end
    
      config.after(:each) do
        DatabaseCleaner.clean
      end
    
    end
    

    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 to true in spec/spec_helper.rb. Try setting it to false.

    0 讨论(0)
提交回复
热议问题