getting “SQLite3::CorruptException: database disk image is malformed” from rails console

ぃ、小莉子 提交于 2020-01-24 09:29:05

问题


I'm doing Michael Hartl's rails screencast tutorial, and in chapter 7, I'm trying to add a user to the database for reasons of testing the user show page. When I create a user, it gets rolled back with an SQLite3::CorruptException: database disk image is malformed error. Research into this error suggests stopping the "postfix" process, but I don't have postfix installed. Any ideas? Please note, I'm new at this and it's very possible a simple mistake on my part! Thanks!

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 >`

回答1:


It sounds like the database has gotten corrupted. You can start from scratch using:

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



回答2:


For me, Nothing was working. I deleted all *.sqlite3 files and then ran

rake db:create
rake db:migrate

Then it worked.



来源:https://stackoverflow.com/questions/15417781/getting-sqlite3corruptexception-database-disk-image-is-malformed-from-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!