Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

ruby on rails - SQLite3 Error - cannot rollback - no transaction is active

SOLVED (see below)

When I'm trying to create or destroy a record (running on SQLite3) in my Ruby on Rails app (or in console as well) I'm getting 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 saves into the database but also throws this kind of error. I tried to delete my DB then create and migrate it again, but it doesn't appear to make any good.

I would really appreciate any ideas on how to fix it. I've never faced such thing before =(

SOLUTION

I've destroyed my model and created another one. Must be some conflict in attribute names, as the new one now has fp:string contents:text and works nicely. Might be the word hash that ruined SQLite =) Thank y'all!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Holy smokes... The situation is in-fact that the field name "hash" causes sqlite3 to throw this very unhelpful error. Tricky one...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...