Rails db:migrate:reset生成Errno :: EACCES权限被拒绝@unlink_internal

时间:2016-09-09 15:21:15

标签: ruby-on-rails ruby sqlite rubygems railstutorial.org

我正在关注Michael Hartl的Rails教程,并且在某些方面我们要运行 rails db:migrate:reset
但是,每次我尝试这样做时,我都面临有关文件

的权限被拒绝错误
  

development.sqlite3

我尝试过以下我遇到的解决方案:
1. close all programs suspected of using said file and retry task
2. terminate rails console, server, editor and retry task
3. shut/restart pc and executing the task upon restart
4. executing rails db:drop

所有这些都无法允许命令运行。唯一可行的解​​决方案是手动删除文件并运行rails db:migrate

我正在运行

  

Rails 5.0.0.1
  Ruby 2.2.5p319
  Sqlite3 3.14.1
  Windows 10专业版

我的堆栈跟踪是:

  

**调用db:migrate:reset(first_time)
  **调用db:drop(first_time)
  **调用db:load_config(first_time)
  **执行db:load_config
  **调用db:check_protected_environments(first_time)
  **调用环境(first_time)
  **执行环境
  **调用db:load_config
  **执行db:check_protected_environments
  **执行db:drop
  **调用db:drop:_unsafe(first_time)
  **调用db:load_config
  **执行db:drop:_unsafe
  权限被拒绝@ unlink_internal - %path%/ sample_app / db / development.sqlite3   无法删除数据库&db; development.sqlite3'
  铁轨已中止!
  Errno :: EACCES:权限被拒绝@ unlink_internal - %path%/ sample_app / db / development.sqlite3
  C:/Ruby22-x64/lib/ruby/2.2.0/fileutils.rb:1450:在remove_file'中的unlink'
C:/Ruby22-x64/lib/ruby/2.2.0/fileutils.rb:1450:in
块中   C:/Ruby22-x64/lib/ruby/2.2.0/fileutils.rb:1458:在platform_support'
C:/Ruby22-x64/lib/ruby/2.2.0/fileutils.rb:1449:in
remove_file'
  C:/Ruby22-x64/lib/ruby/2.2.0/fileutils.rb:793:在remove_file'
C:/Ruby22-x64/lib/ruby/2.2.0/fileutils.rb:571:in
块中的rm'
  C:/Ruby22-x64/lib/ruby/2.2.0/fileutils.rb:570:在each'
C:/Ruby22-x64/lib/ruby/2.2.0/fileutils.rb:570:in
rm'
  C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/tasks/sqlite_database_tasks.rb:22:in drop'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/tasks/database_tasks.rb:136:in
drop'
  C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/tasks/database_tasks.rb:152:在each_current_configuration中的block in drop_current'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/tasks/database_tasks.rb:292:in
块中&#39; <登记/>   C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/tasks/database_tasks.rb:291:in each'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/tasks/database_tasks.rb:291:in
each_current_configuration&#39;
  C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/tasks/database_tasks.rb:151:在drop_current'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/railties/databases.rake:42:in
区块(2级)中& #39;
  C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:248:在call'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:248:in
块中执行&#39;
  C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:243:在each'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:243:in
执行&#39;
  C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:187:in block in invoke_with_call_chain'
C:/Ruby22-x64/lib/ruby/2.2.0/monitor.rb:211:in
mon_synchronize&#39;
  C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:180:在invoke_with_call_chain'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:173:in
调用&#39;
  C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/railties/databases.rake:38:in block (2 levels) in <top (required)>'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:248:in
来电&#39;
  C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:248:block in execute'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:243:in
每个&#39;
  C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:243:in execute'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:187:in
块in invoke_with_call_chain&#39;
  C:/Ruby22-x64/lib/ruby/2.2.0/monitor.rb:211:在mon_synchronize'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:180:in
invoke_with_call_chain&#39;
  C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:209:block in invoke_prerequisites'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:207:in
每个&#39;
  C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:207:在invoke_prerequisites'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:186:in
块中的invoke_with_call_chain&#39;
  C:/Ruby22-x64/lib/ruby/2.2.0/monitor.rb:211:在mon_synchronize'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:180:in
invoke_with_call_chain&#39;
  C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:173:在invoke'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/application.rb:152:in
invoke_task&#39;
  C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/application.rb:108:block (2 levels) in top_level'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/application.rb:108:in
每个&#39;
  C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/application.rb:108:在block in top_level'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/application.rb:117:in
run_with_threads&#39;
  C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/application.rb:102:在run_rake_task的top_level'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/commands/rake_proxy.rb:13:in
块中&#39;
  C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/application.rb:178:在standard_exception_handling'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/commands/rake_proxy.rb:10:in
run_rake_task&#39;
  C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:51:in run_command!'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in
&#39;
  bin / rails:4:require'
bin/rails:4:in
&#39;
  任务:TOP =&gt; db:drop:_unsafe

如何删除此错误并阻止其用于未来的项目?

2 个答案:

答案 0 :(得分:8)

使用Windows 10 Pro时出现同样的错误红宝石2.4.1 | Rails 5.1.4。我喜欢使用:

rake db:drop:_unsafe
rake db:create
rake db:migrate

答案 1 :(得分:0)

在Windows 10,Ruby 2.6.0,Rails 5.2.2上,按照本书中的步骤操作此命令,我遇到了同样的问题。我也在该数据库上同时使用DB Browser for SQLite。

关闭浏览器,rails服务器以及仍在使用数据库的所有其他内容之后,即使重新启动后,我仍然收到错误消息。

为了解决该问题,我不得不通过Windows手动删除development.sqlite3文件,然后执行rails db:migrate