15
13

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.

SQLite3::BusyException: database is locked:のエラーの解決

Last updated at Posted at 2017-05-05

SQLite3::BusyException: database is locked:のエラーの解決

環境
rails 5.0.2

lendモデルを作ろうとして、最後にrake db:migrateをしたら、以下のエラーが出た。

エラー
SQLite3::BusyException: database is locked: CREATE TABLE "lends" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "user_id" integer, "book_id" integer, "begin" datetime, "finish" datetime, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)

解決法1
 ターミナルを開いて、rails cでコンソールを開いて、以下を打つ。

コンソール
   ActiveRecord::Base.connection.execute("BEGIN TRANSACTION; END;")

打ったら、エラーが直った。

解決法2
 エラーが出ているモデルが、他の関係が間違っている。

user.rb
dependent:destroy

付け加える

参考
http://stackoverflow.com/questions/7154664/ruby-sqlite3busyexception-database-is-locked

15
13
1

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
15
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?