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

后端 未结 6 911
感情败类
感情败类 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条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-29 18:26

    You can use rake db:reset when you want to drop the local database and start fresh with data loaded from db/seeds.rb. This is a useful command when you are still figuring out your schema, and often need to add fields to existing models.

    Once the reset command is used it will do the following: Drop the database: rake db:drop Load the schema: rake db:schema:load Seed the data: rake db:seed

    But if you want to completely drop your database you can use rake db:drop. Dropping the database will also remove any schema conflicts or bad data. If you want to keep the data you have, be sure to back it up before running this command.

    This is a detailed article about the most important rake database commands.

提交回复
热议问题