\"source\"=>{\"description\"=>\"We had an issue.\" \"errors\"=>[{\"resource\"=>\"\" \"messages\"=>[\"Error 1292: Incorrect datetime value: '0000-00-00' for column 'last_scaled_at' at row 1\"]}]} \"http\"=>{\"uri\"=>\"https://sys.domain/v2/service_instances/aa7f9416-e768-4777-b173-f1554408fb5d/service_bindings/349c6185-c238-4507-96e9-d8cf5a8e5ae2?accepts_incomplete=true\" \"method\"=>\"PUT\" \"status\"=>500}}}"
This can occur when using GCP for the External RDS.
The default SQL_MODE
in MySQL 5.7 is:
ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
That makes MySQL for VMware Tanzu operate in “strict
” mode for transactional tables.
“Strict mode controls how MySQL handles invalid or missing values in data-change statements such as INSERT
or UPDATE
. A value can be invalid for several reasons. For example, it might have the wrong data type for the column, or it might be out of range. A value is missing when a new row to be inserted does not contain a value for a non-NULL
column that has no explicit DEFAULT
clause in its definition. (For a NULL
column, NULL
is inserted if the value is missing.) Strict mode also affects DDL statements such as CREATE TABLE.”
http://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sql-mode-strict
That also brings up an interesting problem with the default value for the date/datetime column. Let’s say we have the following table in MySQL for VMware Tanzu 5.7, and want to insert a row into it:
mysql> CREATE TABLE `events_t` ( -> `id` int(11) NOT NULL AUTO_INCREMENT, -> `event_date` datetime NOT NULL, -> `profile_id` int(11) DEFAULT NULL, -> PRIMARY KEY (`id`), -> KEY `event_date` (`event_date`), -> KEY `profile_id` (`profile_id`) -> ) ENGINE=InnoDB DEFAULT CHARSET=latin1 -> ; Query OK, 0 rows affected (0.02 sec) mysql> insert into events_t (profile_id) values (1); ERROR 1364 (HY000): Field 'event_date' doesn't have a default value
The event_date does not have a default value, and we are inserting a row without a value for event_date
. That causes an error in MySQL for VMware Tanzu 5.7. If we can’t use NULL, we will have to create a default value. In strict mode we can’t use “0000-00-00” either:
mysql> alter table events_t change event_date event_date datetime NOT NULL default '0000-00-00 00:00:00'; ERROR 1067 (42000): Invalid default value for 'event_date' mysql> alter table events_t change event_date event_date datetime NOT NULL default '2000-00-00 00:00:00'; ERROR 1067 (42000): Invalid default value for 'event_date'
We have to use a real date:
mysql> alter table events_t change event_date event_date datetime NOT NULL default '2000-01-01 00:00:00'; Query OK, 0 rows affected (0.00 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> insert into events_t (profile_id) values (1); Query OK, 1 row affected (0.00 sec)
By default, MySQL for VMware Tanzu 5.7 is much “stricter” than older versions of MySQL for VMware Tanzu. That can make your application fail. To temporarily fix this, change the SQL_MODE
to NO_ENGINE_SUBSTITUTION
(same as in MySQL for VMware Tanzu 5.6):
mysql> set global SQL_MODE="NO_ENGINE_SUBSTITUTION";