2014-12-03 108 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