ActiveRecord :: StatementInvalid: SQLite3 :: BusyException: database is locked

Introduction

I'm learning the rails tutorial. Many errors encountered during test execution during learning

RuntimeError:         RuntimeError: database is locked
ActiveRecord::StatementInvalid:         ActiveRecord::StatementInvalid: SQLite3::BusyException: database is locked

Now that these can be avoided, I will write them down.

By the way, as an aside, up to Chapter 9, even if this error occurs, it will be repeated several times.

rails test

Then I was able to pass it about the 5th time. (It was very troublesome) However, no matter how many times I executed it in Chapter 9, I could not pass it.

What I tried

① At the rails console

ActiveRecord::Base.connection.execute("BEGIN TRANSACTION; END;")

Run

Result no effect

② In the database.yml file, change the timeout value from 5000 to 15000

Result no effect

③ Rename the db / test.sqlite3 file

#sample_app/In the db directory
mv test.sqlite3 new.test.sqlite3

Copy with the same file name as the original.

cp -p new.test.sqlite3 test.sqlite3

Erase new.test.sqlite3 file

Result no effect

④ Move to DB Browser for SQLite and execute the following shortcut Ctrl + S (I think you can also use [File] to [Write Changes] in the upper left. By the way, I couldn't click because there were no changes. I tried Ctrl + S with the command even though I knew it was meaningless. T) Just in case Ctrl + Shift + S

After executing the two shortcuts, quit DB Browser for SQLite, quit all terminals, etc. once, and restart.

Result no effect

⑤ In the test / test_help.rb file

#Probably about the 8th and 9th lines
parallelize(workers: :number_of_processors, with: :threads)

Comment out

# parallelize(workers: :number_of_processors, with: :threads)

As a result, no error was displayed and the test passed !!

Reference article

①②④ https://stackoverflow.com/questions/58854780/what-does-the-database-is-locked-error-message-mean-in-ruby-on-rails-testing ③ http://fanblogs.jp/scripts/archive/61/0 ⑤ https://stackoverflow.com/questions/58854780/what-does-the-database-is-locked-error-message-mean-in-ruby-on-rails-testing (last answer)

At the end

I hope it will be helpful for those who are suffering from the same error.

Recommended Posts

ActiveRecord :: StatementInvalid: SQLite3 :: BusyException: database is locked
What to do if you get a SQLite3 :: BusyException: database is locked error
ActiveRecord :: StatementInvalid (SQLite3 :: SQLException: no such table: main.follows ~