Mysql and inserting '' (empty not null) in datetime column - mysql

I have a system that insert some datetime field as an empty string '' and it works. However, i tried to install in a different machine and it fails.
It returns
Error Code: 1292. Incorrect datetime value: '' for column 'MyDate' at row 1 0.000 sec
btw, i can't change the system and both system (the working one and the new one) runs on windows.

Disable STRICT_MODE (which is enabled by default on Windows installations)

Related

MySQL rejecting date

MySQL 8
My query:
"UPDATE `users` SET `start_date` = '2007-04-09' AND `eligibility` = 1 WHERE `user_id` = 36;
I am getting the following error:
Warning: #1292 Truncated incorrect DOUBLE value: '2007-04-09'
I checked the type for the start_date field and it it set to date.
When I check the row, I find that it has NOT been modified, even though this is a warning.
I am using the PHPMyAdmin interface to interact with the MySQL DB/Server.
Any ideas?
ANSWER:
The answer is that I used an AND statement, instead of a comma. I have not used MySQL for a while. I use ORM instead, so I did not notice the error, and the error message threw me off.
You are setting start_date to:
'2007-04-09' AND `eligibility` = 1
You need a comma instead of AND there if you want to set eligibility too.
That specific message comes because '2007-04-09' AND interprets that string as a Boolean, which it is calling a DOUBLE.

"Field doesn't have a default value" without strict mode

I have a table with a column that is filled by a before insert trigger, this column is set to be NOT NULL and has no DEFAULT VALUE.
When I do a INSERT TABLE without passing this column, I receive the error: 1364 - Field 'column_name' doesn't have a default value. I'd search the web for a solution and have encountered this question: Field 'id' doesn't have a default value?. I then checked and changed the mysql_mode from:
"STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION"
to:
"NO_ENGINE_SUBSTITUTION"
but the insert query still returns the same error.
What should I do to bypass this "strict" mode? Or is it something else?
Please let me know if I need to include any config variable. I'm using mysql 5.6.39.
This is a known bug for the mysql 5.6.39 version. And has been fixed since version 5.7.

MySQL: Error #1067 when trying to add a boolean column with default 0

I'm developing a feature to show to the users how many unread messages there is on the site. So I'm trying to execute this query:
alter table messages add read boolean not null default 0
But the server returns this message:
#1067 - Invalid default value for 'Data'
I can't see what is wrong. I'm running MariaDB/MySQL 5.7.20-0ubuntu0.16.04.1.
Found the problem. The "Data" column is with a invalid default value. I got this database restored from a server that has a different MySQL version.

mysql auto increment field error 1336 Incorrect integer value

Recently upgraded to mysql 5.6.30,
throwing out mysql auto incrment error
1366 - Incorrect integer value: '' for column 's
Probably your new Mysql installation runs on strict mode while your previous one did not.And you probably have an empty value in some column which is defined as integer so you get this error.
Go at your my.cnf/my.ini file and look for this line
sql-mode = "STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
Change it to blank:
sql-mode=""
This would disable the strict mode and the error would be converted to warning
BUT
the best aprroach would to be to change the empty field value to a valid integer value.

MySQL - Field <myfield> doesn't have a default value

I am aware that the certain field doesn't have a default value.
I've been using MySQL 5.5.28 and it does work whenever I insert without specifying a value on that field. The field is TINYINT and by default, without specifying any value AND without declaring a default value during creation of the table, a value of 0 will be inserted in that field during INSERT statement.
However, after updating to MySQL 5.5.30, the query doesn't work anymore and is returning Field doesn't have a default value.
I've been looking through the changelogs and didn't find any clue that something has changed with regards to the default values of Integer.
MySQL 5.5.29 : http://dev.mysql.com/doc/relnotes/mysql/5.5/en/news-5-5-29.html#mysqld-5-5-29-feature
MySQL 5.5.30 : http://dev.mysql.com/doc/relnotes/mysql/5.5/en/news-5-5-30.html
Test queries:
MyTable has the Fields MyField1 and MyField2
INSERT INTO MyTable(MyField2)VALUES('MICHAEL');
Result on MySQL 5.5.28:
MyField1 | MyField2
0 | MICHAEL
With warning: 1 row(s) affected, 1 warning(s): 1364 Field 'MyField1' doesn't have a default value
Result on MySQL 5.5.30:
No changes on data and throws an error
Error Code: 1364. Field 'MyField1' doesn't have a default value
INSERT INTO MyTable(MyField1, MyField2)VALUES(0, 'MICHAEL');
The above query will work though.
In the 1st server strict sql mode was not enabled, while in the 2nd one it was. Read more about strict mode in the mysql documentation.
Specifically:
If strict mode is not in effect, MySQL inserts adjusted values for invalid or missing values and produces warnings (see Section 13.7.5.40, “SHOW WARNINGS Syntax”). In strict mode, you can produce this behavior by using INSERT IGNORE or UPDATE IGNORE.