2016-04-29 144 views
0

我对heroku和postgresql有点新东西,不知道如何从mysql转换到postgresql。 我的申请于MySQL和从Heroku的运行发展我做了一些步骤:1. 增加了gem 'pg'gem 'rails_12factor'这样的:在heroku上运行rails项目

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

和捆绑它没有生产 2.我也改变了我的数据库。阳明海运到: (我也有问题,我怎么能在生产中使用的MySQL在devolepment和postgre?)

# 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 

但是! 当我tryed通过Heroku的工作(下载正常工作)我的动态页面wasnt工作,我得到这个错误: Errors

所以,我猜DB只是不迁移,OK,我通过控制台这个拼命地跑: 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中将生产和开发数据库分开?

谢谢,任何帮助!

+0

请确保你有所有的迁移文件..检查使用'bin/rake db:migrate:status'我认为有一个不好。 – siegy22

+0

我应该在heroku或应用程序上检查它? – 01ghost13

+0

在你的本地应用程序 – siegy22

回答

3

首先你必须在heroku上创建数据库。

heroku run rake db:create --app-name 

然后,您可以运行迁移。

+0

我试过了,得到这个:'FATAL:权限被拒绝用于数据库“postgres” 细节:用户没有CONNECT权限。 ' – 01ghost13

+0

你可以显示你的database.yml文件吗? – margo

+0

这是在我的话题 – 01ghost13