Hello!
There is a table and there is a column in it, the type of which is enum because of it all problems arise.
I use the following method to perform the necessary manipulations with table entries (insert / update).

public void AddParametersString(MySqlCommand command, string[] variables, MySqlDbType[] mySqlDbTypes, string[] values) { int i = 0, j=0; foreach (string val in values) command.Parameters.Add(variables[i++], mySqlDbTypes[j++]).Value = val; } 

When I try to add or change an entry, the following error occurs:

 Data truncated for column 'department' at row 1 

This column is of enum type whose values ​​are:

ENUM('Хлебо-булочный', 'Молочный', 'Колбасный', 'Мясной', 'Рыбный', 'Кондитерский', 'Овощной', 'Фруктовый', 'Кулинария', 'Полуфабрикаты', 'Вино-водочный', 'Бакалея')

Why it happens? How to solve this problem? Thanks in advance!)

  • one
    Probably the size of the column was not enough. - msi
  • The size of the column in the MySql table itself ?! The column 'department' datatype is the value ENUM () - Andrey Kogut
  • Is he right in the ENUM database? Most likely not, just emulation in ORM - vp_arth

1 answer 1

The size

If this field is in the VARCHAR database, you need to increase the length of this field so that it is enough for all possible values ​​emulated in ORM Enum .
Usually the length is also indicated in the annotations to the model field.

Type of

The same error can occur when you pass a NULL value to a non- nullable field. Add a nullable flag to the field, or check the code for null and throw the appropriate exception / handle this case.

Value

Ensure that the values ​​passed are in the ENUM data field. You use Russian-language values, so, among other things, check the encodings.

  • Transmitted values ​​are present. They were removed from the ENUM dataset itself when it was inserted or updated. Codings are also checked utf-8 Type field ENUM () As for types, everything is fine: department enum('Хлебо-булочный','Молочный','Колбасный','Мясной','Рыбный','Кондитерский','Овощной','Фруктовый','Кулинария','Полуфабрикаты','Вино-водочный','Бакалея') DEFAULT NULL, What then can be? - Andrey Kogut
  • An empty string can also be transmitted ... Did you find out with what particular value the error occurs? - vp_arth
  • Everything has already become clear. Thank. My fault was. - Andrey Kogut
  • Anyway thanks for the help. A lot of things useful today for ENUM found out. - Andrey Kogut