我正在关注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:1458:在
C:/Ruby22-x64/lib/ruby/2.2.0/fileutils.rb:1450:inplatform_support'
remove_file'
C:/Ruby22-x64/lib/ruby/2.2.0/fileutils.rb:1449:in
C:/Ruby22-x64/lib/ruby/2.2.0/fileutils.rb:793:在remove_file'
块中的rm'
C:/Ruby22-x64/lib/ruby/2.2.0/fileutils.rb:571:in
C:/Ruby22-x64/lib/ruby/2.2.0/fileutils.rb:570:在each'
rm'
C:/Ruby22-x64/lib/ruby/2.2.0/fileutils.rb:570:in
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/tasks/sqlite_database_tasks.rb:22:indrop'
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
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'
块中&#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
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/tasks/database_tasks.rb:292:ineach'
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:291:in
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'
区块(2级)中& #39;
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/railties/databases.rake:42:in
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:248:在call'
块中执行&#39;
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:248:in
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:243:在each'
执行&#39;
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:243:in
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:187:inblock in invoke_with_call_chain'
mon_synchronize&#39;
C:/Ruby22-x64/lib/ruby/2.2.0/monitor.rb:211:in
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:180:在invoke_with_call_chain'
调用&#39;
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:173:in
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/railties/databases.rake:38:inblock (2 levels) in <top (required)>'
来电&#39;
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:248:in
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:248:block in execute'
每个&#39;
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:243:in
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:243:inexecute'
块in invoke_with_call_chain&#39;
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:187:in
C:/Ruby22-x64/lib/ruby/2.2.0/monitor.rb:211:在mon_synchronize'
invoke_with_call_chain&#39;
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:180:in
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:209:block in invoke_prerequisites'
每个&#39;
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:207:in
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:207:在invoke_prerequisites'
块中的invoke_with_call_chain&#39;
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:186:in
C:/Ruby22-x64/lib/ruby/2.2.0/monitor.rb:211:在mon_synchronize'
invoke_with_call_chain&#39;
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:180:in
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:173:在invoke'
invoke_task&#39;
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/application.rb:152:in
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'
每个&#39;
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/application.rb:108:in
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/application.rb:108:在block in top_level'
run_with_threads&#39;
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/application.rb:117:in
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/application.rb:102:在run_rake_task的top_level'
块中&#39;
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/commands/rake_proxy.rb:13:in
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/application.rb:178:在standard_exception_handling'
run_rake_task&#39;
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/commands/rake_proxy.rb:10:in
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:51:inrun_command!'
&#39;
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in
bin / rails:4:require'
&#39;
bin/rails:4:in
任务:TOP =&gt; db:drop:_unsafe
如何删除此错误并阻止其用于未来的项目?
答案 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