Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails db:migrate:reset producing Errno::EACCES Permission denied @unlink_internal

I am following the Rails Tutorial by Michael Hartl, and at certain points we are to run
rails 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:in unlink'
C:/Ruby22-x64/lib/ruby/2.2.0/fileutils.rb:1450:in
block in remove_file'
C:/Ruby22-x64/lib/ruby/2.2.0/fileutils.rb:1458:in 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:in remove_file'
C:/Ruby22-x64/lib/ruby/2.2.0/fileutils.rb:571:in
block in rm'
C:/Ruby22-x64/lib/ruby/2.2.0/fileutils.rb:570:in 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:in 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
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: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'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/tasks/database_tasks.rb:151:in 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
block (2 levels) in '
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:248:in call'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:248:in
block in execute'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:243:in each'
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 block in invoke_with_call_chain'
C:/Ruby22-x64/lib/ruby/2.2.0/monitor.rb:211:in
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'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:173:in
invoke'
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
call'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:248:in block in execute'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:243:in
each'
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
block in invoke_with_call_chain'
C:/Ruby22-x64/lib/ruby/2.2.0/monitor.rb:211:in 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'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:209:in block in invoke_prerequisites'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:207:in
each'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:207:in invoke_prerequisites'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:186:in
block in invoke_with_call_chain'
C:/Ruby22-x64/lib/ruby/2.2.0/monitor.rb:211:in 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'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/task.rb:173:in invoke'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/application.rb:152:in
invoke_task'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/application.rb:108:in 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
each'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/application.rb:108:in 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'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/application.rb:102:in 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
block in run_rake_task'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/application.rb:178:in 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'
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
'
bin/rails:4:in require'
bin/rails:4:in
'
Tasks: TOP => db:drop:_unsafe

How can I remove this error and prevent it for future projects?

like image 344
Chad Mx Avatar asked Sep 09 '16 15:09

Chad Mx


1 Answers

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
like image 157
3 revs, 2 users 80% Avatar answered Sep 29 '22 05:09

3 revs, 2 users 80%