如何清空 Heroku 数据库 [英] How to empty a Heroku database
问题描述
我正在 Heroku 上开发 Ruby on Rails 3 网络应用程序.如何清空数据库?
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
用您的种子数据填充数据库:
To populate the database with your seed data:
$ 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,它因无法创建数据库错误而失败代码>.
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:您可以在 Rails 4 中使用 rake db:setup
.它确实给了您一个 无法创建数据库
code> 错误(因为已经使用 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屋!