从rails控制台获取“SQLite3 :: CorruptException:数据库磁盘映像格式错误”

时间:2013-03-14 18:50:18

标签: ruby-on-rails database sqlite ruby-on-rails-3.2

我正在制作Michael Hartl的视频截屏教程,在第7章中,我试图将用户添加到数据库中,以便测试用户显示页面。当我创建一个用户时,它会回滚到 SQLite3 :: CorruptException:数据库磁盘映像格式错误错误。对此错误的研究表明,停止"后缀"过程,但我没有安装postfix。有任何想法吗?请注意,我是新手,这很可能是我的一个简单错误!谢谢!

1.9.3p194 :009 > user = User.create(name: "dax", email: "poo@foo.bar", password: "lala", password_confirmation: "lala")
(0.1ms)  SAVEPOINT active_record_1
User Exists (0.2ms)  SELECT 1 AS one FROM "users" WHERE LOWER("users"."email") = LOWER('poo@foo.bar') LIMIT 1
SQL (0.6ms)  INSERT INTO "users" ("created_at", "email", "encrypted_password", "name", "salt", "updated_at") VALUES (?, ?, ?, ?, ?, ?)  [["created_at", Thu, 14 Mar 2013 18:29:58     UTC +00:00], ["email", "poo@foo.bar"], ["encrypted_password", "68beb4b809ab79efd7fcbd175a58d7938d595f360df82b85f8f73e209abe6327"], ["name", "dax"], ["salt", "da4687fa5f380d0b1087810fdccfe96fddd4abab4409c2d96adf7c14f6c4b77b"], ["updated_at", Thu, 14 Mar 2013 18:29:58 UTC +00:00]]
(0.1ms)  ROLLBACK TO SAVEPOINT active_record_1
ActiveRecord::StatementInvalid: SQLite3::CorruptException: database disk image is malformed: INSERT INTO "users" ("created_at", "email", "encrypted_password", "name", "salt", "updated_at") VALUES (?, ?, ?, ?, ?, ?)
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/sqlite3-1.3.7/lib/sqlite3/statement.rb:108:in `step'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/sqlite3-1.3.7/lib/sqlite3/statement.rb:108:in `block in each'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/sqlite3-1.3.7/lib/sqlite3/statement.rb:107:in `loop'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/sqlite3-1.3.7/lib/sqlite3/statement.rb:107:in `each'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.12/lib/active_record/connection_adapters/sqlite_adapter.rb:263:in `to_a'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.12/lib/active_record/connection_adapters/sqlite_adapter.rb:263:in `block in exec_query'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.12/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.12/lib/active_record/connection_adapters/sqlite_adapter.rb:242:in `exec_query'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/database_statements.rb:63:in `exec_insert'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/database_statements.rb:90:in `insert'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `insert'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.12/lib/active_record/relation.rb:66:in `insert'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.12/lib/active_record/persistence.rb:367:in `create'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.12/lib/active_record/timestamp.rb:58:in `create'
... 15 levels...
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.12/lib/active_record/attribute_methods/dirty.rb:22:in `save'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.12/lib/active_record/transactions.rb:259:in `block (2 levels) in save'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.12/lib/active_record/transactions.rb:313:in `block in with_transaction_returning_status'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.12/lib/active_record/transactions.rb:208:in `transaction'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.12/lib/active_record/transactions.rb:311:in `with_transaction_returning_status'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.12/lib/active_record/transactions.rb:259:in `block in save'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.12/lib/active_record/transactions.rb:270:in `rollback_active_record_state!'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.12/lib/active_record/transactions.rb:258:in `save'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.12/lib/active_record/persistence.rb:45:in `create'
from (irb):9
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in `start'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in `start'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.12/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'1.9.3p194 :010 >`

2 个答案:

答案 0 :(得分:18)

听起来数据库已经损坏了。您可以使用以下方式从头开始:

rake db:drop
rake db:create
rake db:migrate

答案 1 :(得分:1)

对我来说,没有什么工作。我删除了所有* .sqlite3文件,然后运行

rake db:create
rake db:migrate

然后它奏效了。