ruby on rails - Reset the database , remove the seeds.rb data from database -
how remove seeds.rb data database , added data in seeds.rb though changed ,it not working !!!, how remove data present in database , entered through seeds.rb file ?
if have data seed.rb file in database, should type rake db:seed again after updating seed.rb file.
add line: modelname.delete_all
before creating new records of model.
however, if have other data in database, choose 1 of solutions below:
- manualy remove data using sql query
before line of creating records, add lines removes them. example:
mymodel.where(name: "foo").destroy_all mymodel.create(name: "foo")
use env variable in seed.rb file switch mode:
if env['seedmode'] == 'removedata' #add removing code here else #here should normal seed code
then run seedmode='removedata' rake db:seed