LoginSignup
0
0

More than 1 year has passed since last update.

【エラー備忘録】Windowsローカル環境で$rails db:resetできない場合にマイグレーションを行う手順

Posted at

目次

  • 状況、前提
  • エラー内容
  • 原因
  • 解決方法
  • 参考リンク

状況、前提

Railsでポートフォリオを作成している最中、マイグレーションしなおそうと$rails db:resetした際にエラーにハマる。
Windows 11
Ruby 3.0.2
Rails 6.1.4

エラー内容

Permission denied @ apply2files - C:/myapp/db/development.sqlite3
Couldn't drop database 'db/development.sqlite3'
rails aborted!
Errno::EACCES: Permission denied @ apply2files - C:/myapp/db/development.sqlite3

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

原因

Windowsではrailsコマンドでファイルを削除できないのが原因。

解決方法

Windowsのdelコマンドで一度DBファイルを削除して、マイグレーションする。

$del db\development.sqlite3
$rails db:migrate

シードも更新する場合

$del db\development.sqlite3
$rails db:migrate
$rails db:seed

テスト環境へのマイグレーション

$del db\test.sqlite3
$rails db:migrate RAILS_ENV=test

参考リンク

0
0
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
0
0