ruby-on-rails – SQLite3错误 – 无法回滚 – 没有事务处于活动状态

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – SQLite3错误 – 无法回滚 – 没有事务处于活动状态前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
解决(见下文)

当我试图在我的Ruby on Rails应用程序(或在控制台中)创建或销毁记录(在sqlite3上运行)时,我得到一个sql异常:

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">]

记录保存到数据库中,但也会抛出此类错误.我试图删除我的数据库然后再次创建和迁移它,但它似乎没有任何好处.

我真的很感激有关如何修复它的任何想法.我以前从未遇到过这样的事情=(

我摧毁了我的模型并创建了另一个模型.必须在属性名称中有一些冲突,因为新的现在有fp:string contents:text并且工作得很好.可能是破坏sqlite的词哈希=)谢谢你们!

解决方法

神圣抽烟……实际情况是,字段名称“hash”会导致sqlite3抛出这个非常无用的错误.棘手的……

猜你在找的Ruby相关文章