21
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

$ rails db:migrate:reset できない windows

Posted at

$ rails db:migrate:reset できないときのたい処理法(windows)

Railsチュートリアル10章をやってる途中、コマンドラインで$ rails db:migrate:resetを打ったがエラーが出た。


$ rails db:migrate:reset

Permission denied @ apply2files - C:/Ruby_program/sample_app/db/development.sqlite3
Couldn't drop database 'db/development.sqlite3'
rails aborted!
Errno::EACCES: Permission denied @ apply2files - C:/Ruby_program/sample_app/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)

原因

Railsのバグらしく、根本的にwindowsでは自らがアクセスしているファイルを削除できないとのこと

解決策

コマンドで直接、db/development.sqlite3のファイルを消し、db:create db:migrateを行う

$ rm db/development.sqlite3
$ rails db:create db:migrate

こうするとエラーが発生せず、マイグレーションし直すことができた。

まとめ

$ rails db:reset
$ rm db/development.sqlite3
$ rails db:setup

は等しい。また、

$ rails db:migrate:reset
$ rm db/development.sqlite3
$ bin/rails db:create db:migrate

と等しい。

補足

ruby 2.6.3p62 (2019-04-16 revision 67580) [x64-mingw32]
Rails 5.2.3

21
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?