我对heroku和postgresql有点新意,不知道如何将mysql转换为postgresql。
我的应用程序是在mysql上开发的,并且从heroku运行它我做了一些步骤:
1.添加了gem 'pg'
和gem 'rails_12factor'
之类的内容:
group :production do
gem 'pg'
gem 'rails_12factor'
end
并且没有生产捆绑它 2.我还将database.yml更改为: (我也有疑问,我怎么能在devolepment和postgre中使用mysql?)
# PostgreSQL. Versions 8.2 and up are supported.
#
# Install the pg driver:
# gem install pg
# On OS X with Homebrew:
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On OS X with MacPorts:
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
# gem install pg
# Choose the win32 build.
# Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: 5
但是! 当我尝试通过heroku工作(下载工作正常)我的动态页面不工作,我得到这个错误:
所以,我猜测数据库只是没有迁移,好吧,我通过控制台运行:
heroku run rake db:migrate --app name
Aaand我现在有这个错误:
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
PG::UndefinedTable: ERROR: relation "schoolings" does not exist
: ALTER TABLE "students" ADD CONSTRAINT "fk_rails_e33c769d03"
FOREIGN KEY ("schooling_id")
REFERENCES "schoolings" ("id")
我的问题:
1。为什么会这样?部署我的应用时,我是否错过了一些步骤?
2。如何在deployment.yml中分离生产和dev DB?
谢谢,任何帮助!
答案 0 :(得分:3)
首先,你必须在heroku上创建数据库。
heroku run rake db:create --app-name
然后您可以运行迁移。