迁移不工作在Heroku [英] Migrate not working on Heroku

查看:166
本文介绍了迁移不工作在Heroku的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经运行 PG:重置在Heroku和试图运行分贝:迁移,所有迁移运行但迁移失败,出现以下错误和跟踪:

I've run pg:reset on Heroku and on trying to run db:migrate, all migrations run but the migration fails with the following error and trace:

rake aborted!
Error dumping database
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0.rc2/lib/active_record/tasks/postgresql_database_tasks.rb:55:in `structure_dump'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0.rc2/lib/active_record/tasks/database_tasks.rb:142:in `structure_dump'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0.rc2/lib/active_record/railties/databases.rake:288:in `block (3 levels) in <top (required)>'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0.rc2/lib/active_record/railties/databases.rake:51:in `block (2 levels) in <top (required)>'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0.rc2/lib/active_record/railties/databases.rake:45:in `block (2 levels) in <top (required)>'

如可以看到的<一href="https://github.com/rails/rails/blob/master/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb">here有问题的线,它上面的之一是:

As can be seen here the problematic line and the one above it are:

command = "pg_dump -i -s -x -O -f #{Shellwords.escape(filename)} #{search_path} #{Shellwords.escape(configuration['database'])}"
raise 'Error dumping database' unless Kernel.system(command)

这本地工作没有任何问题,无论是在开发和生产环境。

This works locally without any problems, both in development and production environments.

有没有人经历过这样的事?

Has anyone experienced anything like this?

推荐答案

这是这样的,因为它的出现,可以忽略不计了一个有趣的问题。基于这样的事实它试图做一个数据库:结构:转储时,使用SQL作为您的active_record.schema_format。该rake任务分贝:结构:转储会失败在Heroku因为pg_dump的是(意料之中)没有在二进制路径。有趣的是, Heroku的规定的分贝:模式:不支持转储,但如果你设置的模式格式,红宝石,它的工作原理罚款。

This is an interesting bug that, as it turns out, can be ignored. Based on the fact it's attempting to do a db:structure:dump, you are using 'sql' as your active_record.schema_format. The rake task db:structure:dump will fail on heroku because pg_dump is (unsurprisingly) not in the binary path. Interestingly enough, Heroku states that db:schema:dump is not supported but if you set the schema format to ruby, it works fine.

在Rails 3中,转储任务只会产生一个错误的命令的退出code为1。在基于Unix的系统,如果未找到该命令,退出code是127。因此,即使如果pg_dump的命令上轨3失败(它的),将不会引发一个错误,它不会停止rake任务。因此,使用和Rails 3 SQL架构格式,任何人不会有这个问题,因为它会静静的失败。在轨道4的重构适当提高一个错误,如果转储失败的原因分贝:迁移,以提高在Heroku上的错误。然而,尽管与是错误耙中止的DDL实际执行并提交

In Rails 3, the dump task would only raise an error is the exit code of the command was 1. On unix based systems if the command is not found, the exit code is 127. So even if the pg_dump command fails on rails 3 (which it does), it won't raise an error and it won't halt the rake task. So anyone using a sql schema format with Rails 3 wouldn't have this issue because it would fail silently. The refactor in Rails 4 to properly raise an error if the dump failed causes db:migrate to raise an error on Heroku. However, even though it errors with rake aborted the ddl is actually performed and committed.

可能的解决方案:

  • 忽略的误差作为迁移的实际运行。
  • 既然你不关心生产结构转储,设置schema_format红宝石。在配置/环境/ production.rb

config.active_record.schema_format = :ruby

  • 如果您不想更改配置文件中的一些原因:用以下内容燮preSS错误添加rake任务:

  • If for some reason you don't want to change the config file: add a rake task with the following to suppress the error:

    if Rails.env == 'production'
        Rake::Task["db:structure:dump"].clear
    end
    

  • 这篇关于迁移不工作在Heroku的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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