2017-05-11 10 views
0

これに関する質問がありましたが、今までは他の人のために働いていたソリューションのどれも自分のために働いていませんでした。Rails db:Postgresで作成に失敗し、ロールが存在しないときには

実行するために、現在、私の試みは「デシベルレール:作成」私に私のpostgres内

[[email protected] EthansDevcampPortfolio]$ rails db:create --trace EDP_DB_PASSWORD='password1' RAILS_ENV=development 
** Invoke db:create (first_time) 
** Invoke db:load_config (first_time) 
** Execute db:load_config 
** Execute db:create 
FATAL: role "EthansDevcampPortfolio" does not exist 
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "pool"=>5, "database"=>"EthansDevcampPortfolio_development", "username"=>"EthansDevcampPortfolio", "password"=>"password1", "host"=>nil} 
rails aborted! 
ActiveRecord::NoDatabaseError: FATAL: role "EthansDevcampPortfolio" does not exist 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:705:in `rescue in connect' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:701:in `connect' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:220:in `initialize' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:38:in `new' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:38:in `postgresql_connection' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:759:in `new_connection' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:803:in `checkout_new_connection' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:782:in `try_to_checkout_new_connection' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:743:in `acquire_connection' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:500:in `checkout' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:374:in `connection' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:931:in `retrieve_connection' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/connection_handling.rb:116:in `retrieve_connection' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/connection_handling.rb:88:in `connection' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/tasks/postgresql_database_tasks.rb:10:in `connection' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/tasks/postgresql_database_tasks.rb:19:in `create' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/tasks/database_tasks.rb:117:in `create' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/tasks/database_tasks.rb:137:in `block in create_current' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/tasks/database_tasks.rb:304:in `block in each_current_configuration' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/tasks/database_tasks.rb:303:in `each' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/tasks/database_tasks.rb:303:in `each_current_configuration' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/tasks/database_tasks.rb:136:in `create_current' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/railties/databases.rake:27:in `block (2 levels) in <top (required)>' 
/home/ethannicolai/.gem/ruby/gems/rake-12.0.0/lib/rake/task.rb:250:in `block in execute' 
/home/ethannicolai/.gem/ruby/gems/rake-12.0.0/lib/rake/task.rb:250:in `each' 
/home/ethannicolai/.gem/ruby/gems/rake-12.0.0/lib/rake/task.rb:250:in `execute' 
/home/ethannicolai/.gem/ruby/gems/rake-12.0.0/lib/rake/task.rb:194:in `block in invoke_with_call_chain' 
/usr/share/ruby/monitor.rb:214:in `mon_synchronize' 
/home/ethannicolai/.gem/ruby/gems/rake-12.0.0/lib/rake/task.rb:187:in `invoke_with_call_chain' 
/home/ethannicolai/.gem/ruby/gems/rake-12.0.0/lib/rake/task.rb:180:in `invoke' 
/home/ethannicolai/.gem/ruby/gems/rake-12.0.0/lib/rake/application.rb:152:in `invoke_task' 
/home/ethannicolai/.gem/ruby/gems/rake-12.0.0/lib/rake/application.rb:108:in `block (2 levels) in top_level' 
/home/ethannicolai/.gem/ruby/gems/rake-12.0.0/lib/rake/application.rb:108:in `each' 
/home/ethannicolai/.gem/ruby/gems/rake-12.0.0/lib/rake/application.rb:108:in `block in top_level' 
/home/ethannicolai/.gem/ruby/gems/rake-12.0.0/lib/rake/application.rb:117:in `run_with_threads' 
/home/ethannicolai/.gem/ruby/gems/rake-12.0.0/lib/rake/application.rb:102:in `top_level' 
/usr/local/share/gems/gems/railties-5.1.0/lib/rails/commands/rake/rake_command.rb:21:in `block in perform' 
/home/ethannicolai/.gem/ruby/gems/rake-12.0.0/lib/rake/application.rb:178:in `standard_exception_handling' 
/usr/local/share/gems/gems/railties-5.1.0/lib/rails/commands/rake/rake_command.rb:18:in `perform' 
/usr/local/share/gems/gems/railties-5.1.0/lib/rails/command.rb:46:in `invoke' 
/usr/local/share/gems/gems/railties-5.1.0/lib/rails/commands.rb:16:in `<top (required)>' 
bin/rails:4:in `require' 
bin/rails:4:in `<main>' 
PG::ConnectionBad: FATAL: role "EthansDevcampPortfolio" does not exist 
/home/ethannicolai/.gem/ruby/gems/pg-0.20.0/lib/pg.rb:56:in `initialize' 
/home/ethannicolai/.gem/ruby/gems/pg-0.20.0/lib/pg.rb:56:in `new' 
/home/ethannicolai/.gem/ruby/gems/pg-0.20.0/lib/pg.rb:56:in `connect' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:701:in `connect' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:220:in `initialize' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:38:in `new' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:38:in `postgresql_connection' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:759:in `new_connection' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:803:in `checkout_new_connection' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:782:in `try_to_checkout_new_connection' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:743:in `acquire_connection' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:500:in `checkout' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:374:in `connection' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:931:in `retrieve_connection' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/connection_handling.rb:116:in `retrieve_connection' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/connection_handling.rb:88:in `connection' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/tasks/postgresql_database_tasks.rb:10:in `connection' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/tasks/postgresql_database_tasks.rb:19:in `create' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/tasks/database_tasks.rb:117:in `create' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/tasks/database_tasks.rb:137:in `block in create_current' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/tasks/database_tasks.rb:304:in `block in each_current_configuration' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/tasks/database_tasks.rb:303:in `each' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/tasks/database_tasks.rb:303:in `each_current_configuration' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/tasks/database_tasks.rb:136:in `create_current' 
/usr/local/share/gems/gems/activerecord-5.1.0/lib/active_record/railties/databases.rake:27:in `block (2 levels) in <top (required)>' 
/home/ethannicolai/.gem/ruby/gems/rake-12.0.0/lib/rake/task.rb:250:in `block in execute' 
/home/ethannicolai/.gem/ruby/gems/rake-12.0.0/lib/rake/task.rb:250:in `each' 
/home/ethannicolai/.gem/ruby/gems/rake-12.0.0/lib/rake/task.rb:250:in `execute' 
/home/ethannicolai/.gem/ruby/gems/rake-12.0.0/lib/rake/task.rb:194:in `block in invoke_with_call_chain' 
/usr/share/ruby/monitor.rb:214:in `mon_synchronize' 
/home/ethannicolai/.gem/ruby/gems/rake-12.0.0/lib/rake/task.rb:187:in `invoke_with_call_chain' 
/home/ethannicolai/.gem/ruby/gems/rake-12.0.0/lib/rake/task.rb:180:in `invoke' 
/home/ethannicolai/.gem/ruby/gems/rake-12.0.0/lib/rake/application.rb:152:in `invoke_task' 
/home/ethannicolai/.gem/ruby/gems/rake-12.0.0/lib/rake/application.rb:108:in `block (2 levels) in top_level' 
/home/ethannicolai/.gem/ruby/gems/rake-12.0.0/lib/rake/application.rb:108:in `each' 
/home/ethannicolai/.gem/ruby/gems/rake-12.0.0/lib/rake/application.rb:108:in `block in top_level' 
/home/ethannicolai/.gem/ruby/gems/rake-12.0.0/lib/rake/application.rb:117:in `run_with_threads' 
/home/ethannicolai/.gem/ruby/gems/rake-12.0.0/lib/rake/application.rb:102:in `top_level' 
/usr/local/share/gems/gems/railties-5.1.0/lib/rails/commands/rake/rake_command.rb:21:in `block in perform' 
/home/ethannicolai/.gem/ruby/gems/rake-12.0.0/lib/rake/application.rb:178:in `standard_exception_handling' 
/usr/local/share/gems/gems/railties-5.1.0/lib/rails/commands/rake/rake_command.rb:18:in `perform' 
/usr/local/share/gems/gems/railties-5.1.0/lib/rails/command.rb:46:in `invoke' 
/usr/local/share/gems/gems/railties-5.1.0/lib/rails/commands.rb:16:in `<top (required)>' 
bin/rails:4:in `require' 
bin/rails:4:in `<main>' 
Tasks: TOP => db:create 

を次のコンソール、私は\デュを入力したとき、私は戻って ethansdevcampportfolioを取得を取得しています|スーパーユーザー、継承なし、ロール作成、DB作成

私はユーザー名とパスワードを何度も精査しました。

pg_hba.confのは、設定/ database.ymlを

local all   all        trust 

host all   all   127.0.0.1/32   trust 

host all   all   ::1/128    trust 

host all   all   0.0.0.0/0   md5(I even tried this at 'trust') 

のように、私は見ての場所のアイデアを実行している

# PostgreSQL. Versions 9.1 and up are supported. 
# 
# Install the pg driver: 
# gem install pg 
# On OS X with Homebrew: 
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config 
# On OS X with MacPorts: 
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config 
# On Windows: 
# gem install pg 
#  Choose the win32 build. 
#  Install PostgreSQL and put its /bin directory on your path. 
# 
# Configure Using Gemfile 
# gem 'pg' 
# 
default: &default 
    adapter: postgresql 
    encoding: unicode 
    # For details on connection pooling, see Rails configuration guide 
    # http://guides.rubyonrails.org/configuring.html#database-pooling 
    pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 

development: 
    <<: *default 
    database: EthansDevcampPortfolio_development 

    # The specified database role being used to connect to postgres. 
    # To create additional roles in postgres see `$ createuser --help`. 
    # When left blank, postgres will use the default role. This is 
    # the same name as the operating system user that initialized the database. 
    username: EthansDevcampPortfolio 

    # The password associated with the postgres role (username). 
    password: <%= ENV['EDP_DB_PASSWORD'] %> 

    # Connect on a TCP socket. Omitted by default since the client uses a 
    # domain socket that doesn't need configuration. Windows does not have 
    # domain sockets, so uncomment these lines. 
    host: 

    # The TCP port the server listens on. Defaults to 5432. 
    # If your server runs on a different port number, change accordingly. 
    #port: 5432 

    # Schema search path. The server defaults to $user,public 
    #schema_search_path: myapp,sharedapp,public 

    # Minimum log levels, in increasing order: 
    # debug5, debug4, debug3, debug2, debug1, 
    # log, notice, warning, error, fatal, and panic 
    # Defaults to warning. 
    #min_messages: notice 

# 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: EthansDevcampPortfolio_test 

# As with config/secrets.yml, you never want to store sensitive information, 
# like your database password, in your source code. If your source code is 
# ever seen by anyone, they now have access to your database. 
# 
# Instead, provide the password as a unix environment variable when you boot 
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database 
# for a full rundown on how to provide these environment variables in a 
# production deployment. 
# 
# On Heroku and other platform providers, you may have a full connection URL 
# available as an environment variable. For example: 
# 
# DATABASE_URL="postgres://myuser:[email protected]/somedatabase" 
# 
# You can use this database configuration with: 
# 
production: 
    url: <%= ENV['DATABASE_URL'] %> 
# 
production: 
    <<: *default 
    database: EthansDevcampPortfolio_production 
    username: EthansDevcampPortfolio 
    password: <%= ENV['EDP_DB_PASSWORD'] %> 

のように見えます見えます。ポストグルールのインスタンスを1つインストールしてしまったということがありました。私はすべてのことにノブであることを意味するので、dnfリストをインストールして、私はポストグルのインスタンスを1つしか見ませんでした。

どこを見るか、何を試してみるか、誰に尋ねるかについてのアイディアは歓迎されます。

+1

'EthansDevcampPortfolio'の代わりに' username'を 'database.yml'の' ethansdevcampportfolio'に変更してみてください。 – Pavan

答えて

0

config/database.yml

default: &default 
    adapter: postgresql 
    pool: 5 
    timeout: 5000 
    username : db_username 
    password : db_password 

development: 
    <<: *default 
    database: db_name 

test: 
    <<: *default 
    database: db_name 

production: 
    <<: *default 
    database: db_name 

のコード下記の試みは、データベースを作成するには、次のコマンドを実行します。

rake db:create 
0

問題は、データベースがロールの存在を持っていないです。あなたは、あなたは、Postgresのコンソールに移動し、UNIXアカウントの名前(ないデータベース自体の名前を持つスーパーユーザを作成

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

development: 
    <<: *default 
    database: EthansDevcampPortfolio_development 
    username: postgres 
    password: <%= ENV['EDP_DB_PASSWORD'] %> 
0

をデータベースにEthansDevcampPortfolio役割を追加したり、既存のpostgres役割を使用する場合がありますPostgreSQLが動作して、アカウントからUNIX管を介して接続したときに、今)

sudo su postgres 
psql 
postgres=# create user ethannicolai superuser; 
CREATE ROLE 

次に「レールを、」スーパーユーザー権限を持つことになり、正常にDBを作成しています。

また、config/database.ymlの "username"と "password"フィールドを取り出すこともできます。

コンソールのスーパーユーザーである場合は、create databaseでデータベースを作成することもできます.db:createも実行する必要はありませんが、マイグレーションに直接進むことができます。

関連する問題