Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data truncated for column?

After changing the data type of a MySql column in order to store Twilio call ids (34 char strings), I try to manually change the data in that column with:

update calls     set incoming_Cid='CA9321a83241035b4c3d3e7a4f7aa6970d'   where id='1'; 

However I get an error which doesn't make sense seeing as the column's data type was properly modified?

| Level ||| Code | Message | Warning | 1265 | Data truncated for column 'incoming_Cid' at row 1

like image 291
Zagstrug Avatar asked Aug 06 '13 19:08

Zagstrug


People also ask

What is Data truncated for column?

That error means the data is too large for the data type of the MySQL table column.

How do I fix warning 1265 Data truncated for column?

Go to your config/database. php change MySQL strict to false. Show us the migration for the table. It looks to me that the value you are trying to insert into priority is longer than the type specified, hence the truncation.

Why is data truncated?

In databases and computer networks, data truncation occurs when data or a data stream (such as a file) is stored in a location that is too short to maintain its full length.

What does it mean data truncated in MySQL?

TRUNCATE TABLE empties a table completely. It requires the DROP privilege. Logically, TRUNCATE TABLE is similar to a DELETE statement that deletes all rows, or a sequence of DROP TABLE and CREATE TABLE statements. To achieve high performance, TRUNCATE TABLE bypasses the DML method of deleting data.


2 Answers

Your problem is that at the moment your incoming_Cid column defined as CHAR(1) when it should be CHAR(34).

To fix this just issue this command to change your columns' length from 1 to 34

ALTER TABLE calls CHANGE incoming_Cid incoming_Cid CHAR(34); 

Here is SQLFiddle demo

like image 143
peterm Avatar answered Sep 22 '22 02:09

peterm


I had the same problem because of an table column which was defined as ENUM('x','y','z') and later on I was trying to save the value 'a' into this column, thus I got the mentioned error.

Solved by altering the table column definition and added value 'a' into the enum set.

like image 24
MTurPash Avatar answered Sep 20 '22 02:09

MTurPash