2

One of the column in my table was initially created as a varchar(1000). Now there is a need to increase the size of that column to hold around 5000 characters. I used the alter statement to increase the size of that column.

DESC table_name as well as SHOW CREATE TABLE table_name clearly indicates the new size of that column to be 5000 characters. However, interestingly when I try to insert any data exceeding 1000 characters ERROR 1406 (22001) : Data too long for column error shows up.

Out of desperation I changed the datatype to text, and still it's limited to 1000 characters. Any suggestion?

I created an other dummy table with a column size of varchar(5000) and that works just fine.

Engine used is InnoDB and Default Charset is UTF8.

8
  • show your table schema by DESC table_name here .
    – Raptor
    Mar 19, 2013 at 3:46
  • run this query and post results please: 'show full columns from table_name;'
    – Michael Benjamin
    Mar 19, 2013 at 3:49
  • 1
    @MichaelBenjamin : Isn't it supposed to be alter table table_name modify column col_name varchar(newsize)
    – kodi
    Mar 19, 2013 at 18:35
  • It's very interesting coz this problem occurs only in my local sandbox. In the test and production servers, it seems to work fine. And all of them run on exactly the same environment. I believe it could be a MySQL bug.
    – kodi
    Mar 19, 2013 at 18:37
  • @kodi You are correct; alter was for defaults, I always get the alter specification mixed up.. ALTER [COLUMN] col_name {SET DEFAULT literal | DROP DEFAULT} CHANGE [COLUMN] old_col_name new_col_name column_definition [FIRST|AFTER col_name] MODIFY [COLUMN] col_name column_definition [FIRST | AFTER col_name]
    – Michael Benjamin
    Mar 19, 2013 at 20:17

2 Answers 2

4

I had what appeared to be exactly the same problem. I had a column that was VARCHAR(30), and I used ALTER TABLE myTable MODIFY COLUMN myColumn VARCHAR(60) NOT NULL, to double its size. But I kept getting "Error Code: 1406 Data too long for column 'myColumn' at row 1" whenever I tried to insert a value that was > 30 characters. It seemed, somehow, that mySQL had some "memory" of the previous column size, and was still enforcing it, even though INFORMATION_SCHEMA.COLUMNS showed the column's character_maximum_length as the new value, 60. I was convinced it was a mySQL bug.

I eventually discovered the actual problem was that this particular table had a trigger on it, whose purpose was to maintain an audit trail of changes, by populating a similarly-defined myTableHistory table. I had forgotten to do an ALTER TABLE myTableHistory to increase the size of the same column in that table.

1
  • To check for the type of problem I had, the following can be useful: SELECT table_name, data_type, character_maximum_length FROM information_schema.COLUMNS WHERE table_schema='mySchema' AND column_name = 'myColumnName'
    – Bob F
    Dec 12, 2013 at 17:45
0

Use TEXT data type in your case will solve the problem. Remember to remove the SIZE. By default, TEXT data type holds up to 2^16 bytes.

Reference: http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html ( search TEXT )

6
  • 1
    Out of desperation I changed the datatype to text, and still it's limited to 1000 characters.
    – hjpotter92
    Mar 19, 2013 at 3:43
  • No. OP specified the SIZE.
    – Raptor
    Mar 19, 2013 at 3:44
  • Are you sure downvoting this answer is Correct ?
    – Raptor
    Mar 19, 2013 at 3:46
  • 1
    Dunno about the downvote, but the size being specified hasn't been mentioned by OP.
    – hjpotter92
    Mar 19, 2013 at 3:57
  • You're right, as mentioned in my answer, by default, TEXT size is much larger than 1000 characters, therefore it assumes he sets the SIZE to 1000. He probably forgets to remove / modify the size when he changes from VARCHAR to TEXT
    – Raptor
    Mar 19, 2013 at 4:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.