When starting out a new rails project on Windows XP, I ran into a strange problem. I usually do all my development on Mac OSX, but this week I had a need to set up a new project on a XP box. After creating my rails project and a few models. I ran rake db:migrate to set up my development database. All seemed to be going well until I tried to run autotest. Prior to running my test suite, I ran the rake task to set up my test data base with the following result.
> rake db:test:prepare
rake aborted!
Permission denied - db/test.sqlite3
(See full trace by running task with –trace)
The full trace was not much help either. I’m using SQLite in this case, so I thought there may be a problem with the db/test.sqlite3 file in my project. I checked the permissions and everything looked fine. I was even able to connect to the test.sqlite3 data base using the sqlite3 command line and add tables, insert records, etc. Finally I tried to delete the test.sqlite3 file thinking I would just re-create it. Then I get the message from XP telling me that the file can not be deleted because it is being used by another process. Ah ha! Apparently, Aptana Studio had a lock on the file which was causing rake to puke. I closed Aptana Studio and the rake task ran as expected. I did look to make sure that the file was not open in studio first and it was not. Looks like Aptana Studio gets another demerit on the chalkboard today.
{ 3 comments… read them below or add one }
Its possible you had a test console open. This would have a rails stack running which would keep the DB locked. Next time you have this problem, try terminating your test consoles
PS: I’m not affiliated with Aptana
Thanks for the tip AP. I do have auto test running most of the time when I’m working with Rails, so there’s a good chance that could have been part of the problem. I have moved on from Aptana, but I may give it another try one of these days, and I’ll keep that in mind. Thanks again.
I get this error regardless of whether the file is locked by an external application. It looks like Rails will lock it directly. For example:
rake db:test:clone RAILS_ENV=test
causes the permission denied error as you outlined (Ruby 1.8.7, Rails 2.3.8). Doing a trace shows that the ‘purge’ task is failing to delete the file because the file is locked. For some reason, it works on other environments without issue (development, production).