taps icon indicating copy to clipboard operation
taps copied to clipboard

Fixed mysql tinyint length error

Open cayblood opened this issue 14 years ago • 6 comments

Hey Ricardo, can you please check out this fix of mine? I've been experiencing a bug when trying to convert a mysql table that uses tinyint into a sqlite3 database. Recent versions of Sequel convert tinyints into booleans. your code then converts these into the strings "true" or "false", which are too long for the tinyint field length of 1, which causes a length error. This patch tells Sequel not to interpret tinyints as booleans.

Thanks, Carl

cayblood avatar Nov 12 '10 23:11 cayblood

You got some sample mysql or sqlite db dump that I can try it with? Also what version of sqlite & mysql gems are you using

ricardochimal avatar Nov 12 '10 23:11 ricardochimal

Sorry this took so long. Here is a mysql dump that should exercise the problem if you pull it to a sqlite database:

https://gist.github.com/718275

cayblood avatar Nov 27 '10 21:11 cayblood

Bump

cayblood avatar Jan 31 '11 21:01 cayblood

I'm also getting this issue. Here's the error I get when I run heroku db:push:

!!! Caught Server Exception
Taps::InvalidData: Detected data that exceeds the length limitation of its column. This is
generally due to the fact that SQLite does not enforce length restrictions.

Table  : archived_users
Column : wants_adult_gifts
Type   : tinyint(1)
Data   : false

mejibyte avatar Feb 14 '11 14:02 mejibyte

What adapter are you using? the C 'mysql2' gem ? or the C 'mysql' gem ?

ricardochimal avatar Feb 14 '11 22:02 ricardochimal

I'm using the mysql gem (version 2.8.1).

Here's a temporary workaround for this problem. After running this, I was able to heroku db:push successfully: script/dbconsole set sql_mode='STRICT_ALL_TABLES'; alter table archived_users modify wants_adult_gifts int;

(The sql_mode line is to be sure no data is lost in the conversion from tinyint to int).

mejibyte avatar Feb 15 '11 13:02 mejibyte