简体   繁体   中英

Mysql: Set 0000-00-00 to null

I already found How to set to NULL a datetime with 0000-00-00 00:00:00 value? which is exactly my question - however, it does not work.

The colum 'bezahltDatum' is a date field which is nullable 在此输入图像描述

The query

SELECT id,bezahltDatum FROM `officeBuch` WHERE  bezahltDatum = '0000-00-00'

gives 25 results and is working.

However, when I try to convert '0000-00-00' to null with

UPDATE `officeBuch` SET bezahltDatum = null WHERE bezahltDatum = '0000-00-00'

Then I get an error message

#1292 - Incorrect date value: '0000-00-00' for column 'bezahltDatum' at row 1

在此输入图像描述

Why is this not working and how can I fix it? I am using phpMyAdmin Version 4.7.2 and Mysql 5.7.18-0ubuntu0.16.04.1

The only way i can think of is changing the SQL mode temporarily with something like this

SET SESSION sql_mode = 'NO_ENGINE_SUBSTITUTION'; 

before the actual update statement. This will disable the strict mode temporarily and the error should not appear.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM