SQL error (1265): Data truncated for column
| User, date | Message |
|---|---|
|
Written by Soporose
3 years ago Category: General 23 posts since Sat, 25 Jul 09 |
Hi folks. I originally had a VARCHAR column set to a width of 6, but now I want to reduce it to 3. If I make the change in the Table tab of HeidiSQL I get the following error when I click the save button: SQL error (1265): Data truncated for column 'membertype' at row 1 The field "membertype" will only ever consist of a string of three upper case alpha characters. What can I do about this, to make the change and have it stick? |
|
Written by ansgar
3 years ago 3951 posts since Fri, 07 Apr 06 |
Your column "membertype" obviously has one or more values which are longer than 3 chars. That's why you get this message from the server. I believe you are running MySQL in strict mode. Turn it off and the above message should not appear, while that surely cuts of longer values in your membertype column. |
|
Written by Soporose
3 years ago 23 posts since Sat, 25 Jul 09 |
Sorry, I don't know what strict mode is. How do I turn it off and could there be any adverse consequences to doing so? |
|
Written by ansgar
3 years ago 3951 posts since Fri, 07 Apr 06 |
Please check this: SHOW VARIABLES LIKE 'sql_mode' and post the results here. |
|
Written by Soporose
3 years ago 23 posts since Sat, 25 Jul 09 |
Hi anse. I executed that command line in the Query tab and this is all that came up: STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION Is that what you mean? |
|
Written by ansgar
3 years ago 3951 posts since Fri, 07 Apr 06 |
Exactly. STRICT_TRANS_TABLES is what I meant by "strict mode". That forces you to be somehow more disciplined. In this case you have to run an UPDATE on your data and truncate them manually. Then, change the column definition and the error should not pop up. Alternatively, remove STRICT_TRANS_TABLES from the global(!) sql_mode variable (Host > Variables) with a doubleclick, reconnect to the server and apply your changes. |
|
Written by Soporose
3 years ago 23 posts since Sat, 25 Jul 09 |
Will I possibly be setting myself up for future problems by removing the STRICT_TRANS_TABLES entry? |
|
Written by ansgar
3 years ago 3951 posts since Fri, 07 Apr 06 |
This is what the manual says: MySQL Manual wrote: n MySQL 5.0.2 and up, you can select stricter treatment of input values by using the STRICT_TRANS_TABLES or STRICT_ALL_TABLES SQL modes: |
|
Written by Soporose
3 years ago 23 posts since Sat, 25 Jul 09 |
OK, thanks for all your help. |
|
Please login to leave a reply, or register at first. |