How to turn off MySQL strict mode in Rails How to turn off MySQL strict mode in Rails mysql mysql

How to turn off MySQL strict mode in Rails


You can set strict mode in your database.yml using strict: false as follows:

production:  host: ...  username: ...  strict: false

https://api.rubyonrails.org/v4.2.8/classes/ActiveRecord/ConnectionAdapters/MysqlAdapter.html


The mysql2 gem exposes an option to execute an initial command on connect and reconnect. You can set the init_command from inside database.yml:

production:  host: ...  username: ...  init_command: "SET @@SESSION.sql_mode = ''"


You can add this to your database.yml

variables:   sql_mode: 'traditional'

or

variables:   strict_mode: false

See:

https://github.com/rails/rails/pull/8346