ActiveRecord::AdapterNotSpecified database configuration does not specify adapter

后端 未结 7 1775
清歌不尽
清歌不尽 2020-12-06 08:52

When I use heroku open my web app works fine but when I\'m using rails s (localhost) I am running into this error:

ActiveRecord::AdapterNotSpecified database         


        
7条回答
  •  猫巷女王i
    2020-12-06 09:40

    Why are you using a yml node reference in your database.yml?

    You should have something like this:

    #config/database.yml
    development:
      adapter: mysql2
      encoding: utf8
      database: ****
      pool: 5
      username: ****
      password: ****
      host: ***.***.***.*** #-> only for third party db server
    
    production:
      adapter: postgresql
      encoding: utf8
      database: ****
      pool: 5
      username: ****
      password: ****
      host: ***.***.***.*** #-> only for third party db server
    

    Update

    Rails runs using a database. You have to connect to a db to make it work, and to do that you have to define the different connection details in database.yml

    To define the right information, you need to appreciate that Rails operates in several environments - development & production being the two most used

    To get Rails working in your local (development) environment, you need to define the correct db details. This means you need a database to connect to - which is typically done setting up a local mysql / pgsql server

    Bottom line is you connect to a db using:

    • hostname
    • username
    • password
    • db name

    You need to define these in your config/database.yml file

    If you have a server running in your local environment, your database.yml file will look like this:

    #config/database.yml
    development:
      adapter: mysql2
      encoding: utf8
      database: db_name
      pool: 5
      username: username
      password: password
    

提交回复
热议问题