3

我正在学习 Michael Hartl 的 rails 截屏教程,在第 7 章中,出于测试用户显示页面的原因,我正在尝试将用户添加到数据库中。当我创建用户时,它会因SQLite3::CorruptException: database disk image is malformed错误而回滚。对此错误的研究建议停止“后缀”进程,但我没有安装后缀。有任何想法吗?请注意,我是新手,这很可能是我的一个简单错误!谢谢!

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

2 回答 2

18

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

rake db:drop
rake db:create
rake db:migrate
于 2013-03-14T18:59:25.760 回答
2

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

rake db:create
rake db:migrate

然后它起作用了。

于 2017-04-13T21:24:02.460 回答