Ruby on Rails: How can i edit database.yml for postgresql?

前端 未结 7 1211
我寻月下人不归
我寻月下人不归 2020-12-08 06:26

rails new app=>

The current database.yml is like that=>

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your         


        
相关标签:
7条回答
  • 2020-12-08 06:57

    Another way is to have the common values in &default and then have individual values for the other environments, which can be based on environment variables:

    default: &default
      adapter:  postgresql
      encoding: unicode
      port:     <%= ENV.fetch("POSTGRESQL_PORT", "5432") %>
      pool:     <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
      username: <%= ENV['POSTGRESQL_USER_NAME'] %>
      password: <%= ENV.fetch("POSTGRESQL_PASSWORD", "myS3cr3tP4ssw0rd") %>
      host:     <%= ENV['POSTGRESQL_HOST'] %>
    
    development:
      <<: *default
      database: <%= ENV['POSTGRESQL_DB'] %>-development
      host: db
    
    test:
      <<: *default
      database: <%= ENV['POSTGRESQL_DB'] %>-test
      host: db
    
    production:
      <<: *default
      database: <%= ENV['POSTGRESQL_DB'] %>
    

    Here all the values can come from environment variables (if you use Docker or Bitbucket Pipelines) or you can have them in your .env files.

    0 讨论(0)
  • 2020-12-08 06:59

    Simply:

    development:
      adapter: postgresql
      encoding: unicode
      database: blog_development
      pool: 5
      username: blog
      password:
      host: localhost
    

    Source: Configuring Rails Applications

    0 讨论(0)
  • 2020-12-08 07:00

    As Zabba said it's

    development:
      adapter: postgresql
      encoding: unicode
      database: blog_development
      pool: 5
      username: blog
      password:
    

    As mentioned in the Configuring Rails Applications. But you might want an additional min_messages: WARNING, to get rid of the nasty NOTICE messages postgresql gives you during a migration. So my database.yml entry looks like this

    development:
      adapter: postgresql
      encoding: unicode
      database: blog_development
      pool: 5
      username: blog
      password:
      min_messages: WARNING
    
    0 讨论(0)
  • 2020-12-08 07:03
     development:
      adapter: postgresql
      encoding: utf8
      database: name
      username: hading
      password: my_db_password
      host: localhost # not mandatory
      pool: 5 # not mandatory
      timeout: 5000 # not mandatory
    
    0 讨论(0)
  • 2020-12-08 07:06

    Simply use

    rails new app_name --database=postgresql
    

    or if existing application try

     development:
      adapter: postgresql
      encoding: unicode
      database: app_dev
      pool: 5
      username: username
      password: password
      host: localhost
    
    0 讨论(0)
  • 2020-12-08 07:10
    development:
      adapter: postgresql
      encoding: utf8
      database: name
      username: hading
      password: my_db_password
      pool: 5 # not mandatory
      timeout: 5000 # not mandatory
      host: localhost
      port: your postgresql port number (5432 or 5433)
    
    0 讨论(0)
提交回复
热议问题