开发者

Why is rails trucating TEXT column to 65535 chars?

I am saving a ra开发者_如何学JAVAw email in a TEXT column in MySQL with Ruby on Rails. It keeps getting truncated to 65535 characters, does anyone know what causes this?

MySQL is running with max_allowed_packet=64M

Using InnoDB for the storage engine.


It gets truncated to that length because... well, that's what will fit in a TEXT column.

You need MEDIUMTEXT or LONGTEXT if you want to store more than that.


Ruby on Rails didn't truncate, MySQL did.

The TEXT type is limited to 2^16 - 1 = 65535 characters, see the documentation.


65535 is one of those "magic numbers" - it's 2^16 - 1. That's just what the maximum limit is for a TEXT column in MySQL.


I'm not a Ruby expert, but the number 65535 caught my attention -- that's 16 bits (minus 1, which typically is special). You're probably running up against a wall of the size limit of the type you're using.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜