rake db:migrate is throwing BusyException: database is locked exception
I'm going through the Ruby on Rails tutorial by Michael Hartl, and in chapter 6 I am instructed to create a new migration to add an index to the email column in the users table.
Here is my migration:
def self.up
add_index :users, :email, :unique => true
end
def self.down
remove_index :users, :email
end
When I run rake db:migrate it thinks for a second, then throws a Bus开发者_开发百科yException and says the database is locked. The database is a sqlite3 database stored on my local machine in my user folder; nothing special.
Any and all help is greatly appreciated.
I get this all the time, it lies in the fact that sqlite can only be accessed by one process at a time and that the database is locked by that process. Be sure you have no servers or consoles running in another terminal. If you continue to get this, and you are sure there is nothing else accessing that sqlite database (including zombie processes), you can follow the advice here:
How do I unlock a SQLite database?
Almost the same has happended to me. The, simple, solution was exiting from my rails console. It was locking SQLite.
I had the same problem. For me I had the SQLite Database Browser open with the same database which was locking it.
/agree with Christopher
For those of us on unix-based machines, a simple
$: ps -a | grep ruby
$: kill -s 9 XXXX
of ruby processes from terminals I suspected as the culprit did it for me. It was always caused by a console or server that hung in a way that made me kill it and then have to find the 'zombie' process to unlock the db.
On windows it can't be harder than killing a suspect process tree, surely.
The solution to my BusyException
problem, "obvious" in retrospect, was that I did not have write access to SQLite3
database. I had git clone'd a rails project to a windows-served file-system that I was accessing from a Ubuntu box. For whatever reason, Sqlite3
databases were created with +x permission which Sqlite3
must interpret as busy.
It was only after lots of work confirming versions, gems, rubies, etc, that I noticed files permissions were +x.
Granted, an arcane set of circumstances, but I struggled with the problem on/off for two weeks, without finding any help from searching Google, that I thought I would add solution to knowledge base.
For me, Nothing was working. I deleted all *.sqlite3 files and then ran
rake db:create
rake db:migrate
Then it worked.
PS: sqlite3 files are located in db folder of your root directory of rails project
Just had this same issue but the solution was slightly different than above.
$ pgrep -l rails
XXXX ruby
$ kill -s 9 XXXX
精彩评论