Data truncated for column 'diameter' at row 1 on Mysql

9.8k Views Asked by At

Getting an error while trying to insert data into Mysql Table using datamapper ( Codeigniter )

Data truncated for column 'diameter' at row 1
INSERT INTO `purchases` (`bills_id`, `products_id`, `quantity`, `diameter`, `lena`, `lenb`, `lenr`, `thicka`, `thickb`, `widtha`, `widthb`, `boxes`, `resulta`, `resultb`) VALUES (1, 28, '2', '', '', '', '', '', '', '', '', '1', '', 2)

Here is the screenshot of the table

Screenshot

1

There are 1 best solutions below

5
Xpleria On

You're trying to insert an empty string '' into double. You cannot store string in a double column. Make sure the date type is double or compatible (int, float)

Either insert a 0

INSERT INTO `purchases` (`bills_id`, `products_id`, `quantity`, `diameter`, `lena`, `lenb`, `lenr`, `thicka`, `thickb`, `widtha`, `widthb`, `boxes`, `resulta`, `resultb`) VALUES (1, 28, '2', 0, '', '', '', '', '', '', '', '1', '', 2)

or

If there is no value, simply skip it in the query

INSERT INTO `purchases` (`bills_id`, `products_id`, `quantity`, `lena`, `lenb`, `lenr`, `thicka`, `thickb`, `widtha`, `widthb`, `boxes`, `resulta`, `resultb`) VALUES (1, 28, '2', '', '', '', '', '', '', '', '1', '', 2)