The full error is
ActiveRecord::StatementInvalid: Mysql2::Error: SAVEPOINT active_record_1 does not exist: ROLLBACK TO SAVEPOINT active_record_1
I am writing a unit test and getting this error whenever I try to create a new ActiveRecord object -- but only after a certain point. This occurs after these lines:
ActiveRecord::Base.connection.execute "DROP TABLE IF EXISTS foo" ActiveRecord::Base.connection.execute "CREATE TABLE foo (id INTEGER PRIMARY KEY)"
(The table 'foo' will be populated with data if my test succeeds)
Before the above lines, I can write something like
User.create(email => '[email protected]')
and everything works fine. However, if I try writing the above line after my call to ActiveRecord::Base.connection.execute
, then I get this SAVEPOINT error
described above. I've also tried putting my execute statements within a transaction, but that didn't help. I'm stumped.
FYI - I'm using Rails 3.2.8
To solve this issue..
config.use_transactional_fixtures = false
You are using Mysql DDE statements (create/drop/truncate table) which will result in an implicit commit.
Because of the implicit commit, all savepoints of the current transaction are deleted (Refer to above documentation).
To get around this, you can turn off transactions and use DatabaseCleaner (truncation mode).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With