Cloud9 + Rails + Postgresql使用 [英] Cloud9 + rails + Postgresql usage
本文介绍了Cloud9 + Rails + Postgresql使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法使用Postgresql设置Rails应用程序以在Cloud9(c9.io)上进行开发:迁移不会成功。
I can not set up a Rails app using Postgresql for development on Cloud9 (c9.io): the migration does not succeed.
常见错误:
~/workspace (master) $ rake db:migrate
rake aborted!
PG::ConnectionBad: could not connect to server: Connection refused
Is the server running on host "0.0.0.0" and accepting
TCP/IP connections on port 5432?
推荐答案
Cloud9不会通过defalut运行PG。以下是快速&我在C9上使用Postgresql的简单方法:
Cloud9 does not run PG by defalut. Below is the fast & easy way I use to use Postgresql on C9:
1。
Gemfile.rb:
1. Gemfile.rb:
gem 'pg'
2。
Database.yml:
2. Database.yml:
default: &default
adapter: postgresql
encoding: unicode
pool: 5
username: my_name
password: my_pass
host: <%= ENV['IP'] %>
development:
<<: *default
database: my_db_development
test:
<<: *default
database: my_db_test
production:
<<: *default
database: my_db_production
- 将以下代码全部粘贴到控制台中:
`
sudo service postgresql start
sudo sudo -u postgres psql
CREATE USER my_name SUPERUSER PASSWORD 'my_pass';
\q
echo "export USERNAME=my_name"
echo "export PASSWORD=my_pass"
source
bundle
sudo sudo -u postgres psql
UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';
DROP DATABASE template1;
CREATE DATABASE template1 WITH TEMPLATE = template0 ENCODING = 'UNICODE';
UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';
\c template1
VACUUM FREEZE;
\q
bundle exec rake db:create
rake db:migrate
完成!
但是,在几个小时不使用应用程序后,数据库进入了睡眠状态。您必须通过在控制台中键入手动打开 Postgres:
sudo服务postgresql start
这篇关于Cloud9 + Rails + Postgresql使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文