Rails - rake db:reset not clearing my database

2019-08-23 06:51发布

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?

3条回答
戒情不戒烟
2楼-- · 2019-08-23 07:18

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
查看更多
神经病院院长
3楼-- · 2019-08-23 07:30

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.

查看更多
爷的心禁止访问
4楼-- · 2019-08-23 07:36

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.

查看更多
登录 后发表回答