Ruby: SQLite3::BusyException: database is locked:

后端 未结 18 998
感动是毒
感动是毒 2020-11-28 23:29

Ran into this error message whilst developing tonight: SQLite3::BusyException: database is locked:

I have two models:

  • Podcasts have many
相关标签:
18条回答
  • 2020-11-29 00:06

    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

    0 讨论(0)
  • 2020-11-29 00:06

    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)

    0 讨论(0)
  • 2020-11-29 00:10

    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.

    0 讨论(0)
  • 2020-11-29 00:11

    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.

    0 讨论(0)
  • 2020-11-29 00:12

    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
    
    0 讨论(0)
  • 2020-11-29 00:17

    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

    0 讨论(0)
提交回复
热议问题