環境:
- ruby 2.5.9 
- Rails 6.1.7.6 
- spring 3.1.1 
- sqlite3 1.4.4 
rails 專案預設是使用 sqlite ; 因為要練習的關係所以想換成 MySQL
rails6 有新增一個指令可以直接切換 rails 所使用的資料庫種類
https://github.com/rails/rails/issues/34710
rails db:system:change --to=postgresql|mysql|sqlite
但是我卻遇到問題
rails db:system:change --to=mysql
Running via Spring preloader in process 61295
invalid option: --to=mysql
發現是 spring 版本的問題,需要改 spring 的版本
https://github.com/rails/spring/issues/678
改用 rubygems 預設的 版本 1.7.2
https://rubygems.org/gems/spring/versions/1.7.2?locale=zh-TW
編輯 gemfile
gem 'spring', '~> 1.7', '>= 1.7.2'
gem 'mysql2', '~> 0.5'
# 這邊還要再把 sqlite3 1.4.4 換成 mysql2 0.5.5
之後再 bundle install。
下 rails db:system:change --to=mysql
    conflict  config/database.yml
Overwrite /private/tmp/rails_617/mysqlpractice/config/database.yml? (enter "h" for help) [Ynaqdhm] Y
       force  config/database.yml
        gsub  Gemfile
        gsub  Gemfile
恭喜!!!!~~~
已經成功把 sqlite 換成 MySQL 啦~~~
 

 
    
Top comments (0)