Ruby on Rails 数据库配置
示例
Rails项目的数据库配置位于一个文件中config/database.yml。如果您使用railsnew命令创建项目并且未指定要使用的数据库引擎,则rails将sqlite用作默认数据库。database.yml具有默认配置的典型文件将类似于以下内容。
#SQLite版本3.x #宝石安装sqlite3 # #确保在您的Gemfile中定义了SQLite3gem #宝石'sqlite3' # default: &default adapter: sqlite3 pool: 5 timeout: 5000 development: <<: *default database: db/development.sqlite3 # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". #请勿将此数据库设置为与开发或生产相同的数据库。 test: <<: *default database: db/test.sqlite3 production: <<: *default database: db/production.sqlite3
如果要在创建新项目时更改默认数据库,可以指定数据库:railsnewhello_world--database=mysql