如何在heroku中清空数据库 [英] How to empty DB in heroku

查看:118
本文介绍了如何在heroku中清空数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Heroku上的RoR3 webapp上工作。如何清空数据库?

解决方案

如果要使用 SHARED_DATABASE_URL

code>:

  $ heroku pg:reset DATABASE_URL 




$ b 现在到重新创建数据库: $ heroku run rake db:migrate

填充数据库与您的种子数据:

  $ heroku run rake db:seed 

--- OR ---



您可以将最后两个(迁移和种子)通过执行此操作成为一个动作:

  $ heroku run rake db:setup 

编辑 2014-04-18: rake db:setup 不适用于Rails 4,它会以失败而无法创建数据库错误



编辑 2014-10-09:您可以使用 rake d b:setup with Rails 4.它给你一个无法创建数据库错误(因为数据库已经使用 heroku pg:reset 命令)。但它也会在出现错误消息后加载数据库架构和种子。



您可以使用几乎任何rake命令执行此操作,但也有例外。例如, db:reset 不能通过 heroku run rake 工作。您必须使用 pg:reset



更多信息可以在Heroku的文档中找到:



运行Rake命令

a>



重置Postgres DB


Im working on a RoR3 webapp on heroku. How do I empty the database?

解决方案

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

---OR---

You can combine the last two (migrate & seed) into one action by executing this:

$ heroku run rake db:setup

Edit 2014-04-18: rake db:setup doesn't work with Rails 4, it fails with a Couldn't create database error.

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.

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.

More information can be found in Heroku's documentation:

Running Rake Commands

Reset Postgres DB

这篇关于如何在heroku中清空数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆