将Rails应用程序从SQLite3迁移到Postgresql

时间:2017-10-09 05:55:55

标签: ruby-on-rails postgresql heroku sqlite

我试图将我的Rails应用程序的数据库从SQLite3迁移到Postgresql,但一点都不容易找到。我跟随此Railscast(http://railscasts.com/episodes/342-migrating-to-postgresql)。

我已将我的database.yml文件编辑为以下内容:

default: &default
 adapter: postgresql
 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
 timeout: 5000

development:
 <<: *default
 database: db/development.postgresql

test:
 <<: *default
 database: db/test.postgresql

production:
 <<: *default
 database: db/production.postgresql

我在这里所做的就是改变所有说“SQLite3&#39;到了postgresql&#39;。这与Railscast不同,但我猜测它已经过时了(2012)。

我已经安装了gem&#39; pg&#39;,&#39;〜&gt; 0.21.0&#39;,我删除了SQLite3 gem。我已经安装了Postgresql 9.6.3。

接下来我安装了水龙头(0.3.24)。在此之后我尝试了rake db:create:all&#39;但返回的错误消息如下:

fe_sendauth: no password supplied
Couldn't create database for {"adapter"=>"postgresql", "pool"=>5, 
"timeout"=>5000, "database"=>"db/development.postgresql"}
rake aborted!

我在这个网站上读到我可能需要进行Heroku迁移 - &#39; heroku运行rake db:migrate&#39;,但是当我尝试这个时,会返回相同的错误。

我真的不知道这个错误消息的含义 - 我认为它可能与conf_hba文件或pgAdmin有关,但我不明白这些是如何工作的。

非常感谢帮助,谢谢: - )

1 个答案:

答案 0 :(得分:0)

您必须提供password&amp;您文件中的postgres数据库的username为 `

default: &default
    adapter: postgresql
    encoding: unicode
    pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
    timeout: 5000

development: <<: *default database: performance_rails_develop username: postgres password: password pool: 5

test: <<: *default database: performance_rails_test username: postgres password: password

production: <<: *default database: db/production.sqlite3

`

相关问题