No permission to drop SQLite3 development database Rails 5.0 on windows - ruby-on-rails

I am trying to reset my development Database for my Rails 5.0 project on Windows, but when I run (same as rake db:drop)
rails db:drop
I get the following error:
Errno::EACCES Permission denied # unlink_internal
I restarted my PC already to make sure that rails was not running in anyway

You just need to exit the Rails Server.

I had the same error trying to reset my sqlite3 db on Windows, using rails 5.1.6 while doing the Learn Enough to Be Dangerous Rails tutorial. I found the following answer on another post, and it worked for me:
"For Dropping entire database just give rake db:setup it drops and again creates the database for you."
When I run the command, I get:
$ rails db:setup
Database 'db/development.sqlite3' already exists
Database 'db/test.sqlite3' already exists
-- create_table("users", {:force=>:cascade})
-> 0.0497s
-- create_table("users", {:force=>:cascade})
-> 0.0624s
And my database seems to work as expected, but with no data.

This can help
When I need to remove data base then I use rake db:reset.
Please try it.
Hope it helps.

Found Solution:
In windows machine you would have to specify that it is an unsafe move, so i
rake db:drop_unsafe
rails db:migrate
this is for windows machine, if you're using Linux then you can do just
rake db:reset

Related

problem when run rails db:setup : schema.rb doesn't exist yet?

I am newbie with Rails and having this problem.
I created a rails folder named freelancer. Everthing seems ok.
Then, I went to this folder and ran this cmd :
rails db:setup
It said to me this error : /freelancer/db/schema.rb doesn't exist yet. Run rails db*migrate to create it, then try again. If you do not intend to use a database, you should instead alter /home/anh/Desktop/freelancer/config/application.rb to limit the frameworks that will be loaded
Then I ran this command as they said
rails db:migrate
Then I ran the command rails db:setup, they said to me that
Database 'bai9freelancer_development' already exists
Database 'bai9freelancer_test' already exists
I am very confusing because those problem. First, when I create my rails folder freelancer, no problem. Why schema.rb doesn't exist ? Second, They said to me that I must run rails db:migrate then try rails db:setup again, then they said to me that already exists. That why ? Could you please explain those problem for me ? Thank you very much.
When you ran
rails db:migrate
you already created db/schema.rb
Running rails db:setup is the equivalent of
rails db:create
rails db:migrate
rails db:seed
So after you ran rails db:migrate you don't need to recall rails db:setup anymore. You can find out more in the documentation here

Error when running bin/rails test in Vagrant

I'm running the rails-dev-box on Vagrant, with a folder shared between the box and my Windows computer. Rails version 5.0.5. I have a very basic app using a sqlite3 database, and a basic generated scaffold for a model. When I ran bin/rails test I received this error:
ActiveRecord::Tasks::DatabaseAlreadyExists
A link in this GitHub thread pointed to this SO question, and I followed this answer - I edited database.yml to change the location of the databases to a location outside of the shared folder. I then re-migrated the databases with bin/rails db:migrate. This seemed to help a bit, because the next time I ran bin/rails test I received a different error:
Migrations are pending. To resolve this issue, run:
bin/rails db:migrate RAILS_ENV=test
But even after running bin/rails db:migrate RAILS_ENV=test I still receive this error each time I try to run the test.
I think all you need is bin/rails db:test:prepare before bin/rails test

Rails - rake db:reset not clearing my database

New to rails here, and experimenting with using the db\seeds.rb file and such
First, I want to clear all the data in my database using rake db:reset but it's not working!
Here's my output
C:\Sites\sportproject>rake db:reset
Couldn't drop db/development.sqlite3 : #
db/development.sqlite3 already exists
-- create_table("sports", {:force=>true})
-> 0.0640s
-- create_table("teams", {:force=>true})
-> 0.0340s
-- add_index("teams", ["sport_id"], {:name=>"index_teams_on_sport_id"})
-> 0.0160s
-- initialize_schema_migrations_table()
-> 0.0000s
-- assume_migrated_upto_version(20130531012951, ["C:/Sites/sportproject/db/migra
te"])
-> 0.0000s
Then I log into my console with rails console and type Sport.all (Sport is the name of one of my models) and it's showing there's still data!
What am I doing wrong?
I found the answer in Patrik's link.
It's because I'm on windows, as the database is possibly being used by another process, hence the "Permission Denied" message. I just needed to ensure no other processes were using the database.
If you are using Linux and postgresql you can do
sudo service postgresql restart
and then
rake db:reset
I think with mysql is
sudo service mysql restart
I had the same problem. The reason was because I was running the rake db:reset on my IRB or Console. Instead, I quit out of console and run the code again and it worked. Perhaps Itll work for you too.

rake db:seed with Rails/Spree on AppFog

I'm testing a Rails/Spree app on appfog, but I can't get the DB to seed.
I've followed these instructions to the T:
https://docs.appfog.com/languages/ruby/rails
But at the point where I run af tunnel and then open a new terminal window, then run RAILS_ENV=proxied-appfog rake db:seed I get the error
loading fixture /var/lib/gems/1.9.1/gems/spree_core-1.3.2/db/default/spree/countries.yml
rake aborted!
Mysql2::Error: closed MySQL connection: SET FOREIGN_KEY_CHECKS = 1
I'm using MySQL for the db.
Any thoughts on why this is happening?
rake:db migrate runs with no errors.
rake:db reset fails with the same error.
Maybe you run af tunnel, but it is incomplete. You have to run some like af tunnel my-app-mysql-1234 and then select 1 option (none)
Check my recent answer and change the RAILS_ENV=production rake db:migrate per some like RAILS_ENV=production rake db:seed
App Fog Rails Migrate Database
Its work fine for me.
Good luck!

Rake db:create error - cannot load such file -- resque/tasks

setting up existing apps on my new machine.
The first app (a simple one) went ok.
For the second app most things are ok but now getting
Rake aborted!
cannot load such file -- resque/tasks
when trying to run rake db:create
I've installed redis and I believe it is running.
How can I resolve this error?
Ruby 1.9.3 Rails 3.2.8
Installed the resque gem to fix this.

Resources