2014-12-03 159 views
1

我想在heroku上部署我的應用程序。爲此,我從sqlite3更改爲pg,因爲heroku不支持sqlite3。我改變了database.yml中的東西:PostgreSQL用戶與Ruby on Rails

# SQLite version 3.x 
# gem install sqlite3 
# 
# Ensure the SQLite 3 gem is defined in your Gemfile 
# gem 'sqlite3' 
# 
default: &default 
    adapter: postgresql 
    pool: 5 
    timeout: 5000 

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

# Warning: The database defined as "test" will be erased and 
# re-generated from your development database when you run "rake". 
# Do not set this db to the same as development or production. 
test: 
    <<: *default 
    database: db/test.pg 

production: 
    <<: *default 
    database: db/my_database_production.pg 

我也添加了gem並安裝它(gem install pg)。當我嘗試運行打捆EXEC耙分貝:創建它給了我下面的錯誤:

rake aborted! 
ActiveRecord::NoDatabaseError: FATAL: role "flo" does not exist 
Run `$ bin/rake db:create db:migrate` to create your database 
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:898:in `rescue in connect' 
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `connect' 
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:568:in `initialize' 
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new' 
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection' 
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:435:in `new_connection' 
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:445:in `checkout_new_connection' 
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `acquire_connection' 
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:351:in `block in checkout' 
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:350:in `checkout' 
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection' 
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection' 
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:541:in `retrieve_connection' 
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_handling.rb:113:in `retrieve_connection' 
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_handling.rb:87:in `connection' 
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/migration.rb:909:in `initialize' 
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/migration.rb:807:in `new' 
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/migration.rb:807:in `up' 
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/migration.rb:785:in `migrate' 
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>' 
Tasks: TOP => db:migrate 
(See full trace by running task with --trace) 

我想寫蘇 - Postgres的在我的終端,而是從命令我得到:

No passwd entry for user 'postgres' 

我該怎麼辦 ?

+2

將一些PostgreSQL用戶添加到你的'config/database.yml'或編輯'/etc/postgresql/9.x/main/pg_hba.conf'文件並添加你的用戶適當的權限。 – blelump 2014-12-03 16:49:58

+0

@blelump我只有postgres-xc它似乎... – 2014-12-03 16:53:53

+0

真的這是postgres數據庫('database:db/development.pg')的有效方法嗎?我以後再也見不到...... – 2014-12-03 17:03:47

回答

2

您需要將用戶'flo'添加到您本地的postgres實例(我通常只是將它們添加爲超級用戶,所以我沒有權限問題)。在您的終端上運行:

createuser -P -s -e flo 

系統還會提示您設置密碼。現在讓我們使用'flo'。然後,您需要將它添加到您的databases.yml裏的文件:

development: 
    <<: *default 
    database: db/development.pg 
    username: flo 
    password: flo 

做到這一點,然後再次嘗試運行rake db:create。檢查this out for additional help

+1

createuser -P -s -e flo 輸入新角色的密碼: 再次輸入: 7createuser:無法連接到數據庫postgres:FATAL:角色「flo」不存在 – 2014-12-07 13:00:19