如何清空Heroku数据库 [英] How to empty a Heroku database
问题描述
我正在Heroku上开发Ruby on Rails 3 webapp.如何清空数据库?
I'm working on a Ruby on Rails 3 webapp on Heroku. How do I empty the database?
推荐答案
如果使用的是SHARED_DATABASE_URL
,则删除数据库:
To drop the database, if you are using SHARED_DATABASE_URL
:
$ heroku pg:reset DATABASE_URL
现在要重新创建其中没有任何内容的数据库:
Now to recreate the database with nothing in it:
$ heroku run rake db:migrate
要用您的种子数据填充数据库:
$ heroku run rake db:seed
---或---
您可以通过执行以下操作将最后两个(迁移和种子)组合为一个动作:
You can combine the last two (migrate & seed) into one action by executing this:
$ heroku run rake db:setup
编辑 2014-04-18:rake db:setup
不适用于Rails 4,失败,显示Couldn't create database error
.
Edit 2014-04-18: rake db:setup
doesn't work with Rails 4, it fails with a Couldn't create database error
.
编辑:2014-10-09:您可以将rake db:setup
与Rails 4一起使用.它确实会给您一个Couldn't create database
错误(因为数据库已经使用heroku pg:reset
命令创建了) .但是,它还会在错误消息之后加载您的数据库模式和种子.
Edit 2014-10-09: You can use rake db:setup
with Rails 4. It does give you a Couldn't create database
error (because the database was already created using the heroku pg:reset
command). But it also loads your database schema and your seeds after the error message.
您几乎可以使用任何rake命令来执行此操作,但是也有例外.例如,db:reset
不能通过heroku run rake
起作用.您必须改用pg:reset
.
You can do this with pretty much any rake command, but there are exceptions. For example, db:reset
doesn't work via heroku run rake
. You have to use pg:reset
instead.
更多信息可以在Heroku的文档中找到:
More information can be found in Heroku's documentation:
这篇关于如何清空Heroku数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!