# Schema dump does not reflect column size limit

**URL:** <https://www.ruby-forum.com/t/schema-dump-does-not-reflect-column-size-limit/178787>\
**Category:** Rails\
**Created:** [November 11, 2009, 10:55am UTC](https://www.ruby-forum.com/t/schema-dump-does-not-reflect-column-size-limit/178787 "2009-11-11T10:55:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hildegunst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/4bbf92/32.png) [@hildegunst](https://www.ruby-forum.com/u/hildegunst)\
**Post date:** [November 11, 2009, 10:55am UTC](https://www.ruby-forum.com/t/schema-dump-does-not-reflect-column-size-limit/178787/1 "2009-11-11T10:55:43Z")

</div>

Hi,

Everything is in the title.  
With Rails 2.3.4 and MySQL 5.0.41:

If have a table like this:

±---------------±-----------±-----±----±--------±---------------+  
| Field | Type | Null | Key | Default | Extra |  
±---------------±-----------±-----±----±--------±---------------+  
| id | int(11) | NO | PRI | NULL | auto\_increment |  
| author\_id | int(11) | YES | | NULL | |  
| author\_bet\_id | int(11) | YES | | NULL | |  
| author\_comment | text | YES | | NULL | |  
| created\_at | datetime | YES | | NULL | |  
| confirmed | tinyint(1) | YES | | NULL | |  
| admin\_comment | text | YES | | NULL | |  
| confirmed\_at | datetime | YES | | NULL | |  
| bet\_id | int(11) | YES | MUL | NULL | |  
| user\_id | int(11) | YES | MUL | NULL | |  
±---------------±-----------±-----±----±--------±---------------+

But in schema.rb, I have this:

create\_table “abuses”, :force =\> true do |t|  
t.integer “author\_id”  
t.integer “author\_bet\_id”  
t.text “author\_comment”  
t.datetime “created\_at”  
t.boolean “confirmed”  
t.text “admin\_comment”  
t.datetime “confirmed\_at”  
t.integer “bet\_id”  
t.integer “user\_id”  
end

Why the hell is the size limit lost?

---

<div class="post-metadata">

**Author:** ![hildegunst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/4bbf92/32.png) [@hildegunst](https://www.ruby-forum.com/u/hildegunst)\
**Post date:** [November 11, 2009, 2:26pm UTC](https://www.ruby-forum.com/t/schema-dump-does-not-reflect-column-size-limit/178787/2 "2009-11-11T14:26:02Z")

</div>

On Nov 11, 2009, at 4:55 AM, Thomas Gendulphe wrote:

> | Field | Type | Null | Key | Default |  
> | |  
> | user\_id | int(11) | YES | MUL | NULL  
> t.datetime “created\_at”  
> t.boolean “confirmed”  
> t.text “admin\_comment”  
> t.datetime “confirmed\_at”  
> t.integer “bet\_id”  
> t.integer “user\_id”  
> end
> 
> ## Why the hell is the size limit lost?

What size limit is that? Did you mean to show the migration that  
created the table? Since MySQL has no boolean type, it gets  
implemented as tinyint(1) and the default for integer is int(11). Do  
you still thing that there is a problem?

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![hildegunst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/4bbf92/32.png) [@hildegunst](https://www.ruby-forum.com/u/hildegunst)\
**Post date:** [November 12, 2009, 10:16pm UTC](https://www.ruby-forum.com/t/schema-dump-does-not-reflect-column-size-limit/178787/3 "2009-11-12T22:16:46Z")

</div>

Rob B. wrote:

> On Nov 11, 2009, at 4:55 AM, Thomas Gendulphe wrote:
> 
> > | Field | Type | Null | Key | Default |  
> > | |  
> > | user\_id | int(11) | YES | MUL | NULL  
> > t.datetime “created\_at”  
> > t.boolean “confirmed”  
> > t.text “admin\_comment”  
> > t.datetime “confirmed\_at”  
> > t.integer “bet\_id”  
> > t.integer “user\_id”  
> > end
> > 
> > ## Why the hell is the size limit lost?
> 
> What size limit is that? Did you mean to show the migration that  
> created the table? Since MySQL has no boolean type, it gets  
> implemented as tinyint(1) and the default for integer is int(11). Do  
> you still thing that there is a problem?
> 
> -Rob
> 
> Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
> removed\_email\_address@domain.invalid

Actually, the source database, from which schema.rb is created has  
columns, like user\_id, with a type of integer(11).  
In schema.rb, it is dumped as t.integer “user\_id”.  
When I load the schema in another databse, it creates a column user\_id  
with a type of integer(4).

So I am wondering why schema dump is not t.integer “user\_id”, :limit =\>  
11

---

<div class="post-metadata">

**Author:** ![hildegunst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/4bbf92/32.png) [@hildegunst](https://www.ruby-forum.com/u/hildegunst)\
**Post date:** [November 12, 2009, 10:35pm UTC](https://www.ruby-forum.com/t/schema-dump-does-not-reflect-column-size-limit/178787/4 "2009-11-12T22:35:59Z")

</div>

On Wed, Nov 11, 2009 at 1:55 AM, Thomas Gendulphe  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> With Rails 2.3.4 and MySQL 5.0.41:
> 
> | id | int(11) | NO | PRI | NULL | auto\_increment |  
> | author\_id | int(11) | YES | | NULL | |

…

> t.integer “author\_id”  
> t.integer “author\_bet\_id”

> Why the hell is the size limit lost?

## Because it’s basically meaningless? 🙂

via [http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html](http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html) :

Another extension is supported by MySQL for optionally specifying the  
display width of integer data types in parentheses following the base  
keyword for the type (for example, INT(4)). This optional display  
width may be used by applications to display integer values having a  
width less than the width specified for the column by left-padding  
them with spaces. (That is, this width is present in the metadata  
returned with result sets. Whether it is used or not is up to the  
application.)

## The display width does not constrain the range of values that can be stored in the column, nor the number of digits that are displayed for values having a width exceeding that specified for the column. For example, a column specified as SMALLINT(3) has the usual SMALLINT range of -32768 to 32767, and values outside the range allowed by three characters are displayed using more than three characters.

Reading The Fine Manual – priceless 🙂

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan

---

<div class="post-metadata">

**Author:** ![hildegunst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/4bbf92/32.png) [@hildegunst](https://www.ruby-forum.com/u/hildegunst)\
**Post date:** [November 12, 2009, 10:51pm UTC](https://www.ruby-forum.com/t/schema-dump-does-not-reflect-column-size-limit/178787/5 "2009-11-12T22:51:47Z")

</div>

On Nov 12, 2009, at 4:16 PM, Thomas Gendulphe wrote:

> > > t.integer “bet\_id”
> 
> ## So I am wondering why schema dump is not t.integer “user\_id”, :limit =\> 11

Ah! Do those mean an equivalent thing? For example, is one database’s  
“int(11)” a type to hold integers of up to 11 decimal digits and  
another database’s “integer(4)” a type that holds integers in 4  
bytes? Those are the same thing! And you probably wouldn’t want to  
suddenly have 11 BYTE integers in the other (or 4 DIGIT integers in  
the first).

-Rob

(Notwithstanding Hassan’s pointer to the meaning of MySQL’s use of 11  
to indicate the display width.)

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid
