database.yml rails 5

0

Why do I get an error? I'm doing the deploy for production. thanks

database.yml

 production:
     adapter: mysql2
     encoding: utf8
     database: trabajo
     username: root
     password: 987654
     host: localhost
     port: 3306

rails db: create

** error **

rails aborted!

ActiveRecord::AdapterNotSpecified: 'development' database is not configured. Available: ["production"]

o

/home/administrador/.rvm/gems/ruby-2.3.1@rails5/gems/activerecord-5.1.4/lib/active_record/connection_adapters/connection_specification.rb:246:in 'resolve_symbol_connection': 'development' database is not configured. Available: ["production"] (ActiveRecord::AdapterNotSpecified)

This was before

  default: &default
     adapter: sqlite3
        pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
        timeout: 5000

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


    test:
      <<: *default
       database: db/test.sqlite3

    production:
       <<: *default
        database: db/production.sqlite3
    
asked by MIGUEL ANGEL GIL RODRIGUEZ 16.11.2017 в 18:09
source

2 answers

2

In the database.yml file you must configure the database for each environment, the common thing is to have development , test and production .

When you work locally the default environment is development , so Rails looks for the configuration of the database for that environment, however you only have the production configuration.

Then, to solve the error, just add the database configuration development :

development:
  adapter: mysql2
  encoding: utf8
  database: trabajo
  username: root
  password: 987654
  host: localhost
  port: 3306

If you have duplicate values in different environments then you can use default to avoid writing twice the same, for example:

default: &default
  adapter: mysql2
  encoding: utf8
  port: 3306

development:
  <<: *default
  database: trabajo_development
  username: root
  password: 987654
  host: localhost

production:
  <<: *default
  database: trabajo
  username: dbadmin
  password: <%= ENV["DB_PASSWORD"] %>
  host: servidor_produccion
    
answered by 16.11.2017 / 18:24
source
0

By default, rails db:create runs in the development environment. To tell you to execute the action in another environment you have to indicate the environment in the RAILS_ENV variable in the same command which would look like this:

rails db:migrate RAILS_ENV=production
    
answered by 12.04.2018 в 06:47