Greg
Greg

Reputation: 785

Why is rails trucating TEXT column to 65535 chars?

I am saving a raw 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.

Upvotes: 3

Views: 4752

Answers (4)

asbestossupply
asbestossupply

Reputation: 11909

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.

Upvotes: 1

instanceof me
instanceof me

Reputation: 39138

Ruby on Rails didn't truncate, MySQL did.

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

Upvotes: 2

Michael Madsen
Michael Madsen

Reputation: 54999

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.

Upvotes: 13

Matt Ball
Matt Ball

Reputation: 359786

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.

Upvotes: 1

Related Questions