Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails 5 db:reset not working

I want to reset the database of my rails 5 project, but the rails db:reset command is not working.

errormessage:

Permission denied @ unlink_internal - C:/sites5/dawnrebirth/db/development.sqlite3
Couldn't drop database 'db/development.sqlite3'
rails aborted!
Errno::EACCES: Permission denied @ unlink_internal - C:/sites5/dawnrebirth/db/development.sqlite3
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => db:drop:_unsafe
(See full trace by running task with --trace)
like image 895
Max Avatar asked Aug 27 '16 15:08

Max


People also ask

How do I reset a Rails database?

db:reset: Resets your database using your migrations for the current environment. It does this by running the db:drop , db:create , db:migrate tasks. db:rollback: Rolls the schema back to the previous version, undoing the migration that you just ran. If you want to undo previous n migrations, pass STEP=n to this task.

How do I delete a database in Ruby on Rails?

The standard way to delete associated data in Rails is to let ActiveRecord handle it via dependent: :destroy . In the following example, when the parent model ( author ) is deleted, all data in the dependent models will get deleted by ActiveRecord as well. There is an indexed foreign key, but no foreign key constraint.

What does rake db reset?

rake db:migrate - Runs the migrations which haven't been run yet. rake db:reset - Clears the database (presumably does a rake db:drop + rake db:create + rake db:migrate ) and runs migration on a fresh database.

What does db drop do?

The db:drop command drops a database using your current configuration. This command would drop a database named testDB.


1 Answers

Usually when rake db:reset don't run or work for me, I just delete the development.sqlite3 and schema.rb files and re run the rake db:migrate command to regenerate both files. But take note to Never try this in a production environment please.

like image 102
mayorsanmayor Avatar answered Oct 05 '22 23:10

mayorsanmayor