Help us understand the problem. What is going on with this article?

Windowsにてrake db:resetができない

More than 1 year has passed since last update.

失敗したときのログ

Windows環境でdbのリセットを行おうとしたときに、db:resetが失敗した

C:\Users\KTakata\Desktop\tool>bundle exec rake db:reset
Permission denied @ unlink_internal - C:/Users/KTakata/Desktop/tool/db/development.sqlite3
Couldn't drop database 'db/development.sqlite3'
rake aborted!
Errno::EACCES: Permission denied @ unlink_internal - C:/Users/KTakata/Desktop/tool/db/development.sqlite3

Tasks: TOP => db:drop:_unsafe
(See full trace by running task with --trace)

Dropに失敗していた...

Permission denied

Errorを見る限り、development.sqlite3をどこかのプロセスがつかんでいるようだ...

他に起動しているアプリを全て閉じて再実行⇒失敗
PCを再起動して再実行⇒失敗

どないせいっちゅうじゃいん...:umbrella2:

そんなときはErrorMessageを読み返してみよう

...(略)...
Tasks: TOP => db:drop:_unsafe
(See full trace by running task with --trace)

ん??

option :_unsafeを指定して実行

C:\Users\KTakata\Desktop\tool>bundle exec rake db:drop:_unsafe
Dropped database 'db/development.sqlite3'
DEPRECATION WARNING: Passing #original_exception is deprecated and has no effect. Exceptions will automatically capture the original exception. (called from load at C:/Ruby24-x64
in/rake:22)
Database 'db/test.sqlite3' does not exist

Dropが成功したっぽいぞ?

migrate実施

C:\Users\KTakata\Desktop\tool>bundle exec rake db:migrate
== 20170308082654 CreateUsers: migrating ======================================
-- create_table(:users)
...(略)...
== 20170419060402 ChangeNameToProject: migrated (0.0428s) ============

Migrateが最初から実施された⇒Dropに成功してた...

まとめ

どこのプロセスがdevelopment.sqlite3をつかんでいるかはわからなかったが、最後の手段として:_unsafeと言う手がある。
ただし、読んで字の如しなのであまり多様はしたくないところですね。

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away