使用MySQL将rails应用程序部署到Heroku,使用ClearDB addon

时间:2021-05-14 20:41:37

I have a Rails app called "enrollment_app" that initializes and populates all the tables in the database with a MySQL seed file. I built the app, added some migrations and pushed my app to Heroku. However, since Heroku uses Postgres, I need a way to make my MySQL database compatible with Heroku so I am using the ClearDB addon.

我有一个名为“注册_app”的Rails应用程序,它用一个MySQL种子文件初始化并填充数据库中的所有表。我创建了这个应用,添加了一些迁移,并将我的应用推到了Heroku。但是,由于Heroku使用Postgres,所以我需要一种方法使我的MySQL数据库与Heroku兼容,因此我使用ClearDB addon。

When I try to open the app though, I get the message:

当我试着打开应用时,我得到的信息是:

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.

So, I checked the logs and see this error:

我检查了日志,发现了这个错误

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

I've been following along with this tutorial but apparently I don't know how to make ClearDB look like my local MySQL DB since I'm getting that error above. How can I do the equivalent of rake db:seed the MySQL seed file and rake db:migrate to the production ClearDB database?

我一直在学习本教程,但显然我不知道如何使ClearDB看起来像我的本地MySQL DB,因为我得到了上面的错误。如何做与rake db:种子MySQL文件和rake db:迁移到生产ClearDB数据库等价的事情?

Updated - Gemfile:

更新- 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

1 个解决方案

#1


3  

This isn't an issue with ClearDB per se, it looks like you haven't fully divorced from the PostgreSQL defaults. I'd check:

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

  • is pg defined in your Gemfile? it shouldn't be. Instead ensure mysql2 is present.
  • 在Gemfile中定义了pg吗?它不应该。相反,要确保存在mysql2。
  • Have you installed the Heroku ClearDB add-on for this app, and made it the default database your app will use? Have you uninstalled the Heroku Postgres database? See here for complete instructions.
  • 你是否已经为这个应用安装了Heroku ClearDB附加组件,并使它成为你的应用将使用的默认数据库?卸载Heroku Postgres数据库了吗?请参阅这里的完整说明。

Once your Heroku app can connect to the ClearDB database properly, you should be able to set up the database itself with no issues:

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

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

#1


3  

This isn't an issue with ClearDB per se, it looks like you haven't fully divorced from the PostgreSQL defaults. I'd check:

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

  • is pg defined in your Gemfile? it shouldn't be. Instead ensure mysql2 is present.
  • 在Gemfile中定义了pg吗?它不应该。相反,要确保存在mysql2。
  • Have you installed the Heroku ClearDB add-on for this app, and made it the default database your app will use? Have you uninstalled the Heroku Postgres database? See here for complete instructions.
  • 你是否已经为这个应用安装了Heroku ClearDB附加组件,并使它成为你的应用将使用的默认数据库?卸载Heroku Postgres数据库了吗?请参阅这里的完整说明。

Once your Heroku app can connect to the ClearDB database properly, you should be able to set up the database itself with no issues:

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

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