问题描述
是否有rake命令可以清除数据库表中的数据?
如何创建一个DB:种子脚本以将数据预填充数据?
推荐答案
i使用rake db:reset掉落然后重新创建数据库并包含您的seeds.rb文件. http://guides.rubyonrails.org/migrations.html#Resetting-resetting-the-database
其他推荐答案
您可以删除所有内容,并重新创建数据库 +种子:
- rake db:reset:从schema.rb加载
- 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
也将工作
问题描述
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:
- rake db:reset: loads from schema.rb
- 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