I am creating a INSERT script and I am coming across a problem. There is a middle initial field that is a char(1)
Sometimes the records don’t have anything in that field so I put a NULL. This causes a Data too long for column error. I don’t want to just put ‘ ‘ as that leaves just a blanks space.
Is there another way around this?
It sounds like you may be attempting to insert the string
'NULL'into thechar(1)field, rather than an SQL NULL, and you have strict SQL mode enabled, which prevents this being truncated toN.If you are able, run
in the MySQL shell to determine whether your target field accepts NULLs. With no context (are you running this as pure SQL, or connecting to the database from some client program in another langauge?) it’s difficult to provide the exact solution, but you may have something like this:
where ‘NULL’ is simply a string with no special meaning, when what you intend is
Here’s an illustration:
Bit of a punt – apologies if no use …