While trying to insert a record into a certain table, I'm getting an error as follows:
Data truncation: Incorrect datetime value: '0000-00-00 00:00:00' for column 'deleted_at' at row 1
Searching around I found the following questions to be quite insightful:
- MySQL Incorrect datetime value: '0000-00-00 00:00:00'
- Data truncation: Incorrect datetime value: ''
- MySQL: Data truncation: Incorrect datetime value: '2006-10-01 02:22:44'
But I can't take any of the solutions given in these answers because of the following reasons:
- Using any other JAR as mentioned here and here (although this isn't a maven project) isn't an option. I have to use the same jar.
- I can't use anything other than '0000-00-00 00:00:00' for the field
deleted_at
. Apparently, there is a buttload of checking against this. You see, initially, delete_at date can't be set (I would have used a flag likeis_deleted
. If there is a better way please tell me). - And changing MySQL configuration isn't an option like mentioned here. He did a nice job of explaining it. I believe this is the main issue.
As to why you are encountering the issue, it's likely that the sql_mode setting for your session includes
NO_ZERO_DATES
.
I (sadly) don't have much control over these things as I'm not the only one working on this project. To give you an insight about the project, this is how I'm getting the error.
They don't use any logging. Hope you get the picture.
So, given the constraints I'm bound with, is there a way to insert '0000-00-00 00:00:00' other than the solutions given above (I'm hoping maybe using something in JDBC).
MySQL Server Version: 5.7.12-0ubuntu1