Ran into this error message whilst developing tonight: SQLite3::BusyException: database is locked:
I have two models:
actually for me, I found killing rails help to fix this problem.
use "ps aux | grep rails"
to find out ongoing rails process id.
then use
"kill -9 [rails-pid]"
to kill processes.
Then it will work
Try wrap cycle in a single transaction:
def create_tracks
json = Hashie::Mash.new HTTParty.get(self.json_url)
Track.transaction do
json.sections.each do |section|
if section.section_type=="track"
Track.create(:name=>section.track.name, :podcast_id=>self.id)
end
end
end
end
(see Track.transaction)
I had the same
ActiveRecord::StatementInvalid: SQLite3::BusyException: database is locked: INSERT INTO "users" ("created_at", "email", "name", "password_digest", "updated_at") VALUES (?, ?, ?, ?, ?)"
issue. I tried every way around found in Google and I failed. The problem was solved for me when I closed my SQLite Database Browser.
I had the same issue. For those with SQLite Database Browser. I did not need to close SQLite Database Browser. I only had to click the "Write Changes" button. It is highlighted and needs to not be highlighted.
Make sure you don't have 2 guards or several consoles running. If you want make sure desperately see the "No Name's" answer above.
You can also try increasing pool:
for example: change test section in your config/database.yml as below
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 50
timeout: 5000
You may also have enabled threads when parallelizing your tests. Remember to disable the option in test/test_helper.rb
:
parallelize(workers: :number_of_processors, with: :threads)
to
parallelize(workers: :number_of_processors)
https://edgeguides.rubyonrails.org/testing.html#parallel-testing-with-threads