【问题标题】:having trouble running heroku rake db:migrate getting rake aborted! error运行 heroku rake db:migrate 时遇到问题 rake 中止!错误
【发布时间】:2013-10-11 17:48:47
【问题描述】:

我能够推送到 heroku,现在我需要迁移数据库,但我得到了错误 rake 中止!

我运行了命令 heroku rake db:migrate,我的命令行错误是

WARNING: `heroku rake` has been deprecated. Please use `heroku run rake` instead.
Running `rake db:migrate` attached to terminal... up, run.6184
rake aborted!
uninitialized constant MiniTest::Rails
/app/vendor/bundle/ruby/2.0.0/gems/minitest-4.7.5/lib/minitest/unit.rb:19:in `const_missing'
/app/Rakefile:9:in `<top (required)>'
(See full trace by running task with --trace)

然后我运行命令

Running `rake db:migrate` attached to terminal... up, run.8495
rake aborted!
uninitialized constant MiniTest::Rails
/app/vendor/bundle/ruby/2.0.0/gems/minitest-4.7.5/lib/minitest/unit.rb:19:in `const_missing'
/app/Rakefile:9:in `<top (required)>'
(See full trace by running task with --trace)

这是我的 Rakefile 的副本

#!/usr/bin/env rake
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)
require 'rake/dsl_definition'
require 'rake'

Portfolio::Application.load_tasks

MiniTest::Rails::Testing.default_tasks << "features"

这也是我的 Gemfile 的副本

 group :development, :test do
      gem "minitest-rails"
      gem 'sqlite3'
    end

    group :production do
      gem 'pg'
      gem 'rails_12factor'
    end




    group :test do
      gem "minitest-rails-capybara"
    end

    # Gems used only for assets and not required
    # in production environments by default.
    group :assets do
      gem 'sass-rails',   '~> 3.2.3'
      gem 'coffee-rails', '~> 3.2.1'

      # See https://github.com/sstephenson/execjs#readme for more supported runtimes
      # gem 'therubyracer', :platforms => :ruby

      gem 'uglifier', '>= 1.0.3'
    end

    gem 'jquery-rails'

    # To use ActiveModel has_secure_password
    # gem 'bcrypt-ruby', '~> 3.0.0'

    # To use Jbuilder templates for JSON
    # gem 'jbuilder'

    # Use unicorn as the app server
    # gem 'unicorn'

    # Deploy with Capistrano
    # gem 'capistrano'

    # To use debugger
    # gem 'debugger'

有人确定我的问题是什么以及为什么我不能为 heroku 迁移吗?

【问题讨论】:

    标签: ruby-on-rails ruby heroku


    【解决方案1】:

    您的 gemfile 在 :test 组中只有 minitest,这很好,但是您的 rake 文件尝试使用 MiniTest 类。试试这个:

    if Rails.env == "test"
      MiniTest::Rails::Testing.default_tasks << "features"
    end
    

    【讨论】:

      【解决方案2】:

      原因如下:uninitialized constant MiniTest::Rails

      您只为开发和测试环境指定了 minitest-rails。默认情况下,heroku 在生产环境中运行应用程序,并且您没有用于 prod 的 minitest-rails。

      以及一个只为测试运行测试任务的条件:

      MiniTest::Rails::Testing.default_tasks

      【讨论】:

        【解决方案3】:

        jeanaux 和 rb512 绝对是在正确的轨道上,谢谢!

        Heroku 使用 Rakefile,您不能引用 MiniTest:Rails 模块,因为该 gem 仅包含在 Gemfile 的测试和开发组中

        我必须做的是检查测试和开发环境,让 Rake 再次工作。

        if (Rails.env == "test" || Rails.env == "development")
          MiniTest::Rails::Testing.default_tasks << "features"
        end
        

        【讨论】:

        • 感谢@Ivanoats,您的帖子效果很好! rb512 和 jeanaux 你帮助了 heroku,但它在开发中停止工作,现在它在两者都可以工作!
        • 替代方案:在任何地方都包含 minitest-rails gem。查看 gem 的创建者的 cmets,@blowmage:twitter.com/blowmage/status/387034628734738433
        猜你喜欢
        • 2014-03-21
        • 1970-01-01
        • 1970-01-01
        • 2013-03-08
        • 2014-07-10
        • 1970-01-01
        • 1970-01-01
        • 2017-04-16
        • 1970-01-01
        相关资源
        最近更新 更多