重置数据库(清除所有),然后播种一个数据库[英] Reset the database (purge all), then seed a database

本文是小编为大家收集整理的关于重置数据库(清除所有),然后播种一个数据库的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

是否有rake命令可以清除数据库表中的数据?

如何创建一个DB:种子脚本以将数据预填充数据?

推荐答案

i使用rake db:reset掉落然后重新创建数据库并包含您的seeds.rb文件. http://guides.rubyonrails.org/migrations.html#Resetting-resetting-the-database

其他推荐答案

您可以删除所有内容,并重新创建数据库 +种子:

  1. rake db:reset:从schema.rb加载
  2. rake db:drop db:create db:migrate db:seed:从迁移加载

确保您与DB(Rails Server,SQL Client ..)或DB不会下降.

schema.rb是您生成的数据库当前状态的快照:

rake db:schema:dump

其他推荐答案

在Rails 5时,rake命令行工具已被否认为rails,所以现在

rails db:reset而不是rake db:reset

也将工作

本文地址:https://www.itbaoku.cn/post/597386.html

问题描述

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?

推荐答案

I use rake db:reset which drops and then recreates the database and includes your seeds.rb file. http://guides.rubyonrails.org/migrations.html#resetting-the-database

其他推荐答案

You can delete everything and recreate database + seeds with both:

  1. rake db:reset: loads from schema.rb
  2. rake db:drop db:create db:migrate db:seed: loads from migrations

Make sure you have no connections to db (rails server, sql client..) or the db won't drop.

schema.rb is a snapshot of the current state of your database generated by:

rake db:schema:dump

其他推荐答案

As of Rails 5, the rake commandline tool has been aliased as rails so now

rails db:reset instead of rake db:reset

will work just as well