Rails 5 dB: reset does not work

I want to reset my rails 5 project database, but the rails db:reset command does not work.

ErrorMessage:

 Permission denied @ unlink_internal - C:/sites5/dawnrebirth/db/development.sqlite3 Couldn't drop database 'db/development.sqlite3' rails aborted! Errno::EACCES: Permission denied @ unlink_internal - C:/sites5/dawnrebirth/db/development.sqlite3 bin/rails:4:in `require' bin/rails:4:in `<main>' Tasks: TOP => db:drop:_unsafe (See full trace by running task with --trace) 
+7
source share
5 answers

Usually, when rake db:reset does not work or works for me, I simply delete the development.sqlite3 and schema.rb files and re-run the rake db:migrate command to restore both files. But pay attention to Never try this in a production environment, please.

+14
source

It looks like the rails tried to delete the file, but failed. Check the following:

  • Is your application running and connected to a database file? - End the application before doing rake db:reset .
  • Is this some other process (such as a database viewer) associated with the database file? - The same as above completes it to reset.
  • in the worst case (you cannot determine what the file is blocking), rake db:reset immediately after a reboot has a high probability of successful execution.
+1
source

When you do rake db: reset , it launches db: drop and db: setup in sequence.

1. Perhaps you need to stop the Rails server and the console.

2. Rebooting may also solve the problem.

+1
source

I was told to add my entrance for rails 5 as an answer, so on request ...

First stop the rails server.

Secondly, run these 3 commands ...

 rails db:drop rails db:schema:load rails db:reset 

I don’t like copying files, so for me it’s easier and faster than deleting a file. Caution: whether you use my fix or not - always make a backup of your circuit somewhere every day (for example, with a repo system ... github / bitbucket).

I believe that "rake" can be used instead of rails for versions before rails 5, but did not check back on rails 3 or 2.

As @ govind-shaw said ... in any case, you should stop the rail server and start it again.

+1
source

try rails db:drop:_unsafe see https://github.com/rails/rails/issues/31589

0
source

All Articles