6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Railsエラー】SQLite3::CorruptException: database disk image is malformed: ...etc

Posted at

Railstu Torialで、間違ってデータベースを削除してしまい以下のエラーで怒られて調べた結果、解決できたので備忘録として残します。

SQLite3::CorruptException: database disk image is malformed: SELECT name FROM sqlite_master WHERE name <> 'sqlite_sequence' AND name = 'schema_migrations' AND type IN ('table')
Action_Controller__Exception_caught.png

###原因
調べたところ、データベースが破損しているとのことで色んな記事で以下のコマンドを試すとOKとあり、試してみるも解決できず

$ bundle exec rails db:drop
$ bundle exec rails db:create
$ bundle exec rails db:migrate

###解決方法
①**「development.sqlite」「test.sqlite」**のファイルを削除する。

②その後、ターミナルで以下を順にうってみる。

$ bundle exec rails db:create
$ bundle exec rails db:migrate

これで復旧できました。
DB_Browser_for_SQLite_-__Users_ysato_enviroment_sample_app_db_development_sqlite3.png

###参考記事
Railsのデータベースのエラー

6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?