rails 4.2です。
環境はvagrant。
-d mysql
をつけてアプリを作成
$ bundle exec rails new アプリ名 --skip-bundle -d mysql
これで、gemfile
を見てみると、デフォルトだとgemがsqliteのところが、mysqlに変更されている。
config/database.yml
ここもちゃんとデフォルトのsqliteではなく、mysqlに変更されている。
--skip-bundleしているのでgemはまだインストールされていないからする。
けどその前に、
javascriptのruntimeというのがないとbundle exec rake db:create
する時にエラーがでるのでそのtherubyracer
というgemを加える。
therubyracer
はgemfileにもともとあってコメントアウトされているので、コメントアウトをはずすだけで良い。
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# See https://github.com/rails/execjs#readme for more supported runtimes
gem 'therubyracer', platforms: :ruby
$ bundle install
データベースをcreateする
$ rake db:create
これで、もし、
Specified 'mysql2' for database adapter, but the gem is not loaded. Add
gem 'mysql2'to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
というエラーがでたら、
$ bundle update
して、
$ bundle install
。
これで、$ bundle exec rake db:create
。