简体   繁体   中英

rails db:create no password supplied (rails with postgresql)

I am new to Rails. I am trying to start my first Rails project. I run on Windows 10 with PostGreSQL installed. Rail and Ruby versions are installed properly. I then run into the no password supplied error.

Here is my database.yml file

default: &default
adapter: postgresql
encoding: unicode

pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
<<: *default
database: blog_development

test:
<<: *default
database: blog_test

production:
<<: *default
database: blog_production
username: blog
password: password
# old password: <%= ENV['BLOG_DATABASE_PASSWORD'] %>

Thanks guys!

No password supplied error

Each of those blocks represents one environment. Right now if you look you see there is no password for development and test.

development:
<<: *default
database: blog_development

test:
<<: *default
database: blog_test

production:
<<: *default
database: blog_production
username: blog
password: password

I personally set the password and username in the default settings at the top so I only have to write it once. Here is an example.

default: &default
  adapter: postgresql
  encoding: unicode
  username: <%= ENV['DATABASE_USERNAME'] %>
  password: <%= ENV['DATABASE_PASSWORD'] %>
  # 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: DBName_Development

test:
  <<: *default
  database: DBName_Test

production:
  <<: *default
  database: DBName_Production
  username: username
  password: <%= ENV['DATABASE_PASSWORD'] %>

What happens is this line...

<<default

... includes those values in. So now my development and test databases have the username and passwords that I set in the default area. If you look back at yours now there is no username or password getting sent in for your development (and test) database. If you add those values to your default section it should work. In place of my env variables you could just put your values. The values (username and password) are what you use to log in to your database.

Following is the code of database.yml file for connect with postgres db:

default: &default
  adapter: postgresql
  pool: 5
  timeout: 5000
  username : username #username of db
  password : password #password of db, if no password then make it blank

development:
  <<: *default
  database: db_name

test:
  <<: *default
  database: db_name

production:
  <<: *default
  database: db_name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM