[英]How do I exclude data from local table schema_migrations from being pushed to Heroku DB?
I was able to push my Ruby on Rails app with MySQL(local dev) to the Heroku server along with migrating my model with the command heroku rake db:migrate
. 我能够将带有MySQL(local dev)的Ruby on Rails应用程序推送到Heroku服务器,并使用
heroku rake db:migrate
命令迁移模型。 I have also read the documentation on Database Import/Export . 我还阅读了有关数据库导入/导出的文档。 Is that doc referring to pushing actual data from my local dev DB to whichever Heroku's DB?
该文档是否涉及将实际数据从本地开发数据库推送到任何Heroku的数据库? Do I need to modify anything in the file
database.yml
to make it happen? 我是否需要修改文件
database.yml
任何内容以使其实现?
I ran the following command: 我运行了以下命令:
heroku db:push
and I am getting the error: 我收到错误:
Sending data
2 tables, 3 records
!!! Caught Server Exception | ETA: --:--:--
Taps Server Error: PGError ERROR: duplicate key value violates unique constraint
"unique_schema_migrations"
I have 2 tables, one I create for my app and the other schema_migrations
. 我有2个表,一个是为我的应用程序创建的,另一个是
schema_migrations
。 The total number of entries among the 2 tables is 3. I'm also printing the number of entries I have in the table I have created and it's showing 0. 2个表中的条目总数为3。我还将打印我在已创建的表中具有的条目数,并显示0。
Any ideas what I might be missing or what I am doing wrong? 有什么想法可能会丢失或我做错了什么吗?
EDIT: I figured out the above, Heroku's DB already have schema_migrations
the moment I ran migrate. 编辑:我想通了以上内容,我运行迁移的那一刻,Heroku的数据库已经有了
schema_migrations
。
New question: Does anyone know how I can exclude data from a specific table from being pushed to Heroku DB. 新问题:有谁知道我如何才能将特定表中的数据排除在推送到Heroku DB之外。 The table to exclude in this case will be
schema_migrations
. 在这种情况下要排除的表将为
schema_migrations
。
Not so good solution : I googled around and someone else was having the same issue. 不太好的解决方案 :我在Google周围搜索,其他人也遇到了同样的问题。 He suggested naming the
schema_migrations
table to zschema_migrations
. 他建议将
schema_migrations
表命名为zschema_migrations
。 In this way data from the other tables will be pushed properly until it fails on the last table. 这样,来自其他表的数据将被正确推送,直到在最后一个表上失败为止。 It's a pretty bad solution but will do for the time being.
这是一个非常糟糕的解决方案,但暂时可以实现。
A better solution will be to use an existing Rails command which can reset a specific table from a database. 更好的解决方案是使用现有的Rails命令,该命令可以从数据库中重置特定表。 I don't think
Rake
can do that. 我认为
Rake
无法做到。
Two possible options: 两种可能的选择:
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. heroku gem和taps gem(用于同步数据库)都是开源的-您可以将它们分叉,更改taps客户端API以支持从推送中排除表格,然后更改heroku gem以使用该新选项。
You could write a wrapper script that uses pgdump to backup the schema_migrations table, drops that table, heroku push
es the database, then reloads the table. 您可以编写一个包装器脚本,该脚本使用pgdump备份schema_migrations表,删除该表,
heroku push
数据库,然后重新加载该表。
This is kind of a guess based on the error you're getting, but push
looks like it grabs the schema and the data. 这是根据您得到的错误进行的一种猜测,但是
push
看起来像是它获取了架构和数据。 I'd try push to an empty database. 我会尝试推送到一个空数据库。
I've just deployed a Rails 3 beta app to heroku on their new bamboo server. 我刚刚在新的Bamboo服务器上的heroku上部署了Rails 3 beta应用程序。 I can now upload data from my local dev machine to the heroku database by doing:
现在,我可以执行以下操作将数据从本地开发机上载到heroku数据库中:
heroku rake db:fixtures:load test/fixtures/my_model.yml
The data is then properly propagated in the Heroku database. 然后,数据将在Heroku数据库中正确传播。 Even though I specified a specific data file, it automatically pushes data from my other yaml files.
即使我指定了特定的数据文件,它也会自动从其他Yaml文件中推送数据。 It probably has something to do with my model relationships.
这可能与我的模型关系有关。
如果您的数据库不同步,则可以始终先重置Heroku数据库,然后再使用
heroku db:reset
To push/pull from specific tables 从特定表中推/拉
heroku db:pull --tables logs,tags heroku db:pull --tables日志,标签
http://blog.heroku.com/archives/2010/4/21/supporting_big_data_part_1 http://blog.heroku.com/archives/2010/4/21/supporting_big_data_part_1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.