Rails - rake db:reset not clearing my database

我怕爱的太早我们不能终老 提交于 2019-12-11 14:28:10

问题


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?


回答1:


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.




回答2:


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:


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.



来源:https://stackoverflow.com/questions/16860084/rails-rake-dbreset-not-clearing-my-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!