3

我有一个名为“enrollment_app”的 Rails 应用程序,它使用 MySQL 种子文件初始化和填充数据库中的所有表。我构建了应用程序,添加了一些迁移并将我的应用程序推送到 Heroku。然而,由于 Heroku 使用 Postgres,我需要一种方法让我的 MySQL 数据库与 Heroku 兼容,所以我使用 ClearDB 插件。

但是,当我尝试打开该应用程序时,我收到以下消息:

Application Error
An error occurred in the application and your page could not be served. Please try again in a few moments.

If you are the application owner, check your logs for details.

所以,我检查了日志并看到了这个错误:

PG::UndefinedTable: ERROR:  relation "enrollments" does not exist

我一直在关注本教程,但显然我不知道如何使 ClearDB 看起来像我的本地 MySQL DB,因为我在上面遇到了那个错误。如何rake db:seed对 MySQL 种子文件和rake db:migrate生产 ClearDB 数据库进行等效操作?

更新 - Gemfile:

source 'https://rubygems.org'

gem 'rails', '4.2.1'
gem 'mysql2'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'bootstrap-sass', '~> 3.3.5'
gem 'bootswatch-rails'
gem 'ransack'
gem 'jquery-turbolinks'
gem 'kaminari'
gem 'bootstrap-kaminari-views'
gem 'jquery-ui-rails'
gem 'espinita'
gem 'mysqltopostgres', git: "https://github.com/maxlapshin/mysql2postgres.git"

group :development, :test do
  gem 'byebug'
  gem 'web-console', '~> 2.0'
  gem 'spring'
  gem 'rspec-rails'
  gem 'launchy'
  gem 'pry'
  gem 'pry-nav'
  gem 'shoulda-matchers'
  gem 'factory_girl_rails'
  gem 'capybara'
  gem 'newrelic_rpm'
  gem 'poltergeist'
  gem 'database_cleaner'
end

group :production do
  gem 'rails_12factor'
end
4

1 回答 1

3

这不是 ClearDB 本身的问题,看起来您还没有完全脱离 PostgreSQL 默认设置。我会检查:

  • pg在您的 Gemfile中定义?不应该。相反,确保mysql2存在。
  • 您是否为此应用程序安装了 Heroku ClearDB 插件,并将其设置为您的应用程序将使用的默认数据库?您是否卸载了 Heroku Postgres 数据库?有关完整说明,请参见此处

一旦您的 Heroku 应用程序可以正确连接到 ClearDB 数据库,您应该能够毫无问题地设置数据库本身:

heroku run rake db:create
heroku run rake db:migrate
heroku run rake db:seed
于 2015-08-02T13:06:32.767 回答