How to remove the seeds.rb data from database , i added some data in seeds.rb even though i changed ,it is not working !!!, how to remove the data which is present in database , which is entered through the seeds.rb file ?
Asked
Active
Viewed 1,050 times
2
-
did you change or update one or more database tables? – sansarp Apr 23 '15 at 05:55
-
2Check [this](http://stackoverflow.com/questions/14955044/undo-previously-seeded-data-in-rails) – Abhi Apr 23 '15 at 05:59
-
1show your seeds.rd file – jon snow Apr 23 '15 at 06:24
-
cat = MenuLinkCategory.find_by_name("data_and_reports") unless cat.nil? cat.allowed_roles << :alphena_paygrades_view unless cat.allowed_roles.include?(:alphena_paygrades_view) cat.save – Karthik G V Apr 23 '15 at 06:42
-
higher_link=MenuLink.find_or_create_by_name_and_higher_link_id(:name=>'paygrades_text',:target_controller=>'alphena_paygrade',:target_action=>'add_paygrade',:higher_link_id=>nil,:icon_class=>'report-icon',:link_type=>'general',:user_type=>nil,:menu_link_category_id=>cat.id) MenuLink.create(:name=>'alphena_paygrades',:target_controller=>'alphena_paygrades',:target_action=>'add_paygrade',:higher_link_id=>higher_link.id,:icon_class=>nil,:link_type=>'general',:user_type=>nil,:menu_link_category_id=>cat.id) unless MenuLink.exists?(:name=>'alphena_paygrades') end – Karthik G V Apr 23 '15 at 06:42
-
this is seeds.rb file – Karthik G V Apr 23 '15 at 06:43
-
You should check http://stackoverflow.com/questions/14955044/undo-previously-seeded-data-in-rails – floum Apr 23 '15 at 08:27
1 Answers
0
If you have only those data from seed.rb file in your database, you should just type rake db:seed again after updating the seed.rb file.
Add line: ModelName.delete_all
before creating new records of this model.
However, if you have some other data in your database, you could choose one of the solutions below:
- manualy remove data using sql query
before line of creating records, add lines which removes them. For example:
MyModel.where(name: "Foo").destroy_all MyModel.create(name: "Foo")
Use env variable in your seed.rb file to switch mode:
if ENV['seedmode'] == 'removedata' #add removing code here else #here should be normal seed code
Then just run seedmode='removedata' rake db:seed

Seb Wilgosz
- 1,240
- 15
- 24