rails 5 db:reset not working
Asked Answered
U

5

10

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)
Urial answered 27/8, 2016 at 15:13 Comment(1)
Running commands db:drop, db:create, db:migrate one after another fix the issue for me. (And run db:seed if want to populate some test data.)Crate
H
23

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.

Herzen answered 28/8, 2016 at 9:8 Comment(0)
A
6

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

Adverb answered 5/12, 2018 at 14:18 Comment(0)
J
1

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.
Jacklin answered 27/8, 2016 at 22:48 Comment(0)
C
1

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.

Contentment answered 30/8, 2016 at 7:23 Comment(0)
S
1

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.

Siloam answered 16/2, 2017 at 12:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.