I am following the Rails Tutorial by Michael Hartl, and at certain points we are to runrails db:migrate:reset
However each time I do try to do so I am faced with a permission denied error concerning the file
development.sqlite3
I have tried the following solutions I've encountered: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
All of which have failed to allow the command to run. The only working solution is to delete the file manually and running rails db:migrate
I am running
Rails 5.0.0.1
Ruby 2.2.5p319
Sqlite3 3.14.1
Windows 10 Professional
My stack trace is:
** Invoke db:migrate:reset (first_time)
** Invoke db:drop (first_time)
** Invoke db:load_config (first_time)
** Execute db:load_config
** Invoke db:check_protected_environments (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config
** Execute db:check_protected_environments
** Execute db:drop
** Invoke db:drop:_unsafe (first_time)
** Invoke db:load_config
** Execute db:drop:_unsafe
Permission denied @ unlink_internal - %path%/sample_app/db/development.sqlite3 Couldn't drop database 'db/development.sqlite3'
rails aborted!
Errno::EACCES: Permission denied @ unlink_internal - %path%/sample_app/db/development.sqlite3
C:/Ruby22-x64/lib/ruby/2.2.0/fileutils.rb:1450:inunlink'
block in remove_file'
C:/Ruby22-x64/lib/ruby/2.2.0/fileutils.rb:1450:in
C:/Ruby22-x64/lib/ruby/2.2.0/fileutils.rb:1458: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:inremove_file'
block in rm'
C:/Ruby22-x64/lib/ruby/2.2.0/fileutils.rb:571:in
C:/Ruby22-x64/lib/ruby/2.2.0/fileutils.rb:570:ineach'
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:inblock in drop_current'
block in each_current_configuration'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/tasks/database_tasks.rb:292:in
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/tasks/database_tasks.rb:291:ineach'
each_current_configuration'
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:indrop_current'
block (2 levels) in '
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:incall'
block in execute'
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:ineach'
execute'
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'
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:ininvoke_with_call_chain'
invoke'
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)>'
call'
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:inblock in execute'
each'
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'
block in invoke_with_call_chain'
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:inmon_synchronize'
invoke_with_call_chain'
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:inblock in invoke_prerequisites'
each'
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:ininvoke_prerequisites'
block in invoke_with_call_chain'
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:inmon_synchronize'
invoke_with_call_chain'
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:ininvoke'
invoke_task'
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:inblock (2 levels) in top_level'
each'
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:inblock in top_level'
run_with_threads'
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:intop_level'
block in run_rake_task'
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:instandard_exception_handling'
run_rake_task'
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!'
'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in
bin/rails:4:inrequire'
'
bin/rails:4:in
Tasks: TOP => db:drop:_unsafe
How can I remove this error and prevent it for future projects?
I get the same error using Windows 10 Pro | ruby 2.4.1 | Rails 5.1.4. I soved using:
rake db:drop:_unsafe
rake db:create
rake db:migrate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With