尝试从 SQLite 切换到 PostgreSQL

Trying to switch from SQLite to PostgreSQL

我在 Heroku 上的开发和测试中使用 SQLite,在生产中使用 PostgreSQL。我想用 PostgreSQL 替换 SQLite。我在 Cloud9 环境中编程 (Rails 4)。我没有可能丢失的数据。

我做了什么:

首先,我编辑了 database.yml:

default: &default
      adapter: postgresql
      encoding: unicode
      pool: 5
development:
  <<: *default
  database: app_development
test:
  <<: *default
  database: app_test
production:
  <<: *default
  database: app_production

然后:


更新: 我添加了以下附加步骤:

运行 sudo sudo -u postgres psql 然后 \list 产生:

      Name          |  Owner   | Encoding  | Collate | Ctype |   Access privileges   
 postgres           | postgres | SQL_ASCII | C       | C     | 
 template0          | postgres | SQL_ASCII | C       | C     | =c/postgres          +
                    |          |           |         |       | postgres=CTc/postgres
 template1          | postgres | SQL_ASCII | C       | C     | =c/postgres          +
                    |          |           |         |       | postgres=CTc/postgres
 app_development    | postgres | SQL_ASCII | C       | C     | 

我在这里没有看到我作为 app_development...

所有者的用户名

错误: 运行 rake db:migrate 超时,显示 PG::ConnectionBad: could not connect to server: Connection timed out Is the server running on host "myurl.c9.io" (ip address) and accepting TCP/IP connections on port 5432?.

为什么与 PostgreSQL 的连接可能会失败?

将 database.yml 文件的内容替换为:

default: &default
  adapter: postgresql
  host: localhost
  username: yourusername
  password: yourpassword
  timeout: 5000
  port: 5432
development:
  <<: *default
  database: app_development
test:
  <<: *default
  database: app_test
production:
  <<: *default
  database: app_production

因为您使用的是 Heroku,所以您可以保留生产部分原样