Reset the database (purge all), then seed a database

后端 未结 6 905
感情败类
感情败类 2021-01-29 18:09

Is there a rake command to wipe out the data in the database tables?

How do I create a db:seed script to pre-fill data to my tables?

6条回答
  •  闹比i
    闹比i (楼主)
    2021-01-29 18:17

    If you don't feel like dropping and recreating the whole shebang just to reload your data, you could use MyModel.destroy_all (or delete_all) in the seed.db file to clean out a table before your MyModel.create!(...) statements load the data. Then, you can redo the db:seed operation over and over. (Obviously, this only affects the tables you've loaded data into, not the rest of them.)

    There's a "dirty hack" at https://stackoverflow.com/a/14957893/4553442 to add a "de-seeding" operation similar to migrating up and down...

提交回复
热议问题