簡體   English   中英

使用ClearDB插件將使用MySQL的rails應用程序部署到Heroku

[英]Deploy a rails app using MySQL to Heroku using ClearDB addon

我有一個名為“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數據庫,因為我上面得到了這個錯誤。 我怎樣才能相當於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

這不是ClearDB本身的問題,看起來你還沒有完全脫離PostgreSQL默認值。 我檢查一下:

  • 是你的Gemfile中定義的pg 它不應該。 而是確保mysql2存在。
  • 您是否為此應用安裝了Heroku ClearDB插件,並使其成為您的應用將使用的默認數據庫? 你卸載了Heroku Postgres數據庫嗎? 請參閱此處獲取完整說明。

一旦您的Heroku應用程序可以正確連接到ClearDB數據庫,您應該能夠自行設置數據庫而不會出現任何問題:

heroku run rake db:create
heroku run rake db:migrate
heroku run rake db:seed

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM