2

我能够使用 MySQL(本地开发)将我的 Ruby on Rails 应用程序推送到 Heroku 服务器,同时使用命令迁移我的模型heroku rake db:migrate。我还阅读了有关Database Import/Export的文档。该文档是指将实际数据从我的本地开发数据库推送到 Heroku 的任何数据库吗?我是否需要修改文件中的任何内容database.yml才能实现?

我运行了以下命令:

heroku db:push

我得到了错误:

Sending data
2 tables, 3 records
!!! Caught Server    Exception                                   | ETA:  --:--:--
Taps Server Error: PGError ERROR:  duplicate key value violates unique constraint
"unique_schema_migrations"

我有 2 个表,一个是为我的应用程序创建的,另一个是为我的应用程序创建的schema_migrations。2 个表中的条目总数为 3。我还打印了我创建的表中的条目数,它显示为 0。

任何想法我可能会错过什么或我做错了什么?

编辑: 我想通了上面,Heroku 的数据库已经有了schema_migrations我运行迁移的那一刻。

新问题:有谁知道我如何排除特定表中的数据被推送到 Heroku DB。在这种情况下要排除的表将是schema_migrations

不太好的解决方案:我四处搜索,其他人也遇到了同样的问题。schema_migrations他建议将表命名为zschema_migrations. 这样,来自其他表的数据将被正确推送,直到它在最后一个表上失败。这是一个非常糟糕的解决方案,但暂时可以。

更好的解决方案是使用现有的 Rails 命令,该命令可以从数据库中重置特定表。我不认为Rake可以这样做。

4

5 回答 5

1

Two possible options:

  1. The heroku gem and the taps gem (which it uses to synchronize databases) are both open-source - you could fork them, alter the taps client API to support excluding tables from a push, then alter the heroku gem to use that new option.

  2. You could write a wrapper script that uses pgdump to backup the schema_migrations table, drops that table, heroku pushes the database, then reloads the table.

于 2009-08-26T03:51:28.673 回答
0

从特定表推/拉

heroku db:pull --tables 日志、标签

http://blog.heroku.com/archives/2010/4/21/supporting_big_data_part_1

于 2010-08-22T19:38:41.270 回答
0

我刚刚在 Heroku 的新竹服务器上部署了一个 Rails 3 beta 应用程序。我现在可以通过执行以下操作将数据从本地开发机器上传到 heroku 数据库:

heroku rake db:fixtures:load test/fixtures/my_model.yml

然后数据会在 Heroku 数据库中正确传播。即使我指定了一个特定的数据文件,它也会自动从我的其他 yaml 文件中推送数据。这可能与我的模特关系有关。

于 2010-03-21T20:27:49.077 回答
0

这是基于您得到的错误的一种猜测,但push看起来它抓住了架构和数据。我会尝试推送到一个空的数据库。

于 2009-08-24T03:12:52.190 回答
0

如果您的数据库不同步,您始终可以在使用推送之前重置 Heroku 数据库

heroku db:reset
于 2010-07-25T16:30:17.237 回答