问题
I want to reset the database of my rails 5 project, but the rails db:reset
command is not working.
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)
回答1:
Usually when rake db:reset
don't run or work for me, I just delete the development.sqlite3 and schema.rb files and re run the rake db:migrate
command to regenerate both files. But take note to Never try this in a production environment please.
回答2:
try rails db:drop:_unsafe
see https://github.com/rails/rails/issues/31589
回答3:
Looks like rails tried to delete the file but did not succeed. Check the following:
- is your app running and connected to the database file? — Terminate the app before executing
rake db:reset
. - is some other process (for example a database viewer) connected to the database file? — Same as above, terminate it before reset.
- in the worst case (you cannot determine what is blocking the file), a
rake db:reset
immediately after reboot has a high probability to run successfully.
回答4:
When you do rake db:reset, it's running db:drop and db:setup in sequence.
1.Maybe you need to stop your Rails server and console.
2.A reboot may solve the problem too.
回答5:
I was told to add my input for rails 5 as an answer, so by request ...
First, stop the rails server.
Second, run these 3 commands ...
rails db:drop
rails db:schema:load
rails db:reset
I hate digging through files, so this is easier & faster for me than going to delete some file. Caveat: Whether you are using my fix or not - always backup your schema somewhere every day (like with a repo system...github/bitbucket).
I believe 'rake' can be used in place of rails for versions before rails 5, but haven't tested back to rails 3 or 2.
As @govind-shaw said ... either way, you have to stop the rails server & start it up again.
来源:https://stackoverflow.com/questions/39182630/rails-5-dbreset-not-working