Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Data too long for column" - why?

Tags:

sql

mysql

I've written a MySQL script to create a database for hypothetical hospital records and populate it with data. One of the tables, Department, has a column named Description, which is declared as type varchar(200). When executing the INSERT command for Description I get an error:

error 1406: Data too long for column 'Description' at row 1.

All the strings I'm inserting are less than 150 characters.

Here's the declaration:

CREATE TABLE Department(     ...     Description varchar(200)     ...); 

And here's the insertion command:

INSERT INTO Department VALUES (..., 'There is some text here',...), (..., 'There is some more text over here',...); 

By all appearances, this should be working. Anyone have some insight?

like image 302
Ben C. Avatar asked Sep 19 '13 14:09

Ben C.


People also ask

How do I fix a data too long for a column?

That error message means you are inserting a value that is greater than the defined maximum size of the column. The solution to resolve this error is to update the table and change the column size.

How can I change varchar size in MySQL?

Here is how you do it: ALTER TABLE address MODIFY state VARCHAR(20) ; In generic terms, you use the ALTER TABLE command followed by the table name, then the MODIFY command followed by the column name and new type and size.

What is the max length of varchar in MySQL?

Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 65,535. The effective maximum length of a VARCHAR is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used.


1 Answers

Change column type to LONGTEXT

like image 84
Alexander Serkin Avatar answered Sep 24 '22 05:09

Alexander Serkin