SQLite3 error - rollback impossible - transaction inactive

SOLVED (see below)

When I try to create or destroy a record (running on SQLite3) in my Ruby on Rails application (or in the console), I get an SQL exception:

irb(main):014:0> ApiCache.all => [] irb(main):015:0> ApiCache.create(:hash => 'qwe', :contents => 'asd') SQLite3::SQLException: cannot rollback - no transaction is active from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/sqlite3-1.3.3-x86-mingw32/lib/sqlite 3/database.rb:97:in `close' from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/sqlite3-1.3.3-x86-mingw32/lib/sqlite 3/database.rb:97:in `prepare' from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/sqlite3-1.3.3-x86-mingw32/lib/sqlite 3/database.rb:134:in `execute' from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/sqlite3-1.3.3-x86-mingw32/lib/sqlite 3/database.rb:517:in `rollback' from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.6/lib/active_record /connection_adapters/sqlite_adapter.rb:168:in `rollback_db_transaction' from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.6/lib/active_record /connection_adapters/abstract/database_statements.rb:176:in `transaction' from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.6/lib/active_record /transactions.rb:207:in `transaction' from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.6/lib/active_record /transactions.rb:290:in `with_transaction_returning_status' from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.6/lib/active_record /transactions.rb:240:in `save' from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.6/lib/active_record /transactions.rb:251:in `rollback_active_record_state!' from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.6/lib/active_record /transactions.rb:239:in `save' from C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.6/lib/active_record /base.rb:498:in `create' from (irb):15 from :0 irb(main):016:0> ApiCache.all => [#<ApiCache id: 9, hash: "qwe", contents: "asd", created_at: "2011-05-09 13:09:31", updated_at: " 2011-05-09 13:09:31">] 

The record is stored in the database, but also generates such an error. I tried deleting my db and then creating and migrating it again, but it doesn't seem to be doing anything good.

I would really appreciate any ideas on how to fix this. I have never encountered such a thing before = (

DECISION

I destroyed my model and created another. There should be some conflict in the attribute names, since the new one now has fp: string contents: text and works beautifully. Maybe the hash word that destroyed SQLite =) Thanks y'all!

+7
source share
3 answers

Saints smokes ... The situation actually lies in the fact that the field name "hash" causes sqlite3 to throw this very useless error. Tricky one ...

+9
source

It’s a good idea to never create an instance method named hash. It is used by tons of ruby ​​objects for comparison and equality. Regardless of the weather using SQLite or anything else, a custom hash method should only be executed when you know what you want from it. In this case, ActiveRecord has made this method for you. I would rename the column :)

+1
source

Maybe you should try looking here: Rails Tests Fail With Sqlite3 It looks like they found a workaround.

0
source

All Articles