自 MariaDB 10.2 及 MySQL 5.7 起,預設的 SQL Mode 會有所改變 –

由原來預設的 “NO_ENGINE_SUBSTITUTION” ,

改變為 “ONLY_FULL_GROUP_BY, STRICT_TRANS_TABLES, NO_ZERO_IN_DATE, NO_ZERO_DATE, ERROR_FOR_DIVISION_BY_ZERO, NO_AUTO_CREATE_USER, and NO_ENGINE_SUBSTITUTION.”

而其中 STRICT_TRANS_TABLES 的改變較為明顯

If a value could not be inserted as given into a transactional table, abort the statement. For a nontransactional table, abort the statement if the value occurs in a single-row statement or the first row of a multiple-row statement.

例如 –
若一個 NOT NULL 欄位 (column),若無預設值,當新增記錄時,若沒有為這欄位提供資料,
從前,會預設自動寫入為 NULL (無),但可以新增記錄;
現在,根據 STRICT_TRANS_TABLES,它不能新增記錄,其出現錯誤 (exception)

詳情可以參考 –
https://mariadb.com/kb/en/sql-mode/
https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sql-mode-strict

如有必要,您可以在你的 CMS 應用程序中手動添加以下 SQL,以返回原來舊版 SQL Mode

set SQL_MODE = ‘NO_ENGINE_SUBSTITUTION’;

Pin It on Pinterest

Share This