This project is archived and is in readonly mode.
TableDefinition.column ignores :limit for integer types
Reported by Carlos Paramio | January 29th, 2009 @ 04:19 PM | in 2.x
Given a migration like:
class CreateMyModel < ActiveRecord::Migration
def self.up
create_table :my_models, :id => false do |t|
t.column :integer_test1, :integer, :limit => 20
t.integer :integer_test2, :limit => 20
t.string :string_test1, :limit => 20
end
end
end
It generates a schema like:
+---------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| integer_test1 | int(11) | YES | | NULL | |
| integer_test2 | int(11) | YES | | NULL | |
| string_test1 | varchar(20) | YES | | NULL | |
+---------------+--------------+------+-----+---------+----------------+
when the integer columns should be of type int(20). This happens with MySQL and SQLite, so I suspect it is a bug on the column method.
Comments and changes to this ticket
-
Carlos Paramio January 29th, 2009 @ 04:43 PM
I realized that this fails because there isn't any integer type on MySQL with a size of 20 bytes:
ActiveRecord::Base.connection.type_to_sql(:integer, 20) ActiveRecord::ActiveRecordError: No integer type has byte size 20
Please close this ticket.
-
CancelProfileIsBroken August 4th, 2009 @ 06:16 PM
- Tag changed from 2.2.2, activerecord, limit, schema to 2.2.2, activerecord, bugmash, limit, schema
-
Rajesh August 8th, 2009 @ 09:12 PM
+1 for closing this ticket
ActiveRecord::Base.connection.type_to_sql(:integer, 20)
ActiveRecord::ActiveRecordError: No integer type has byte size 20from /Users/rajesh/src/property/trunk/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:535:in `type_to_sql'
but following work fine
ActiveRecord::Base.connection.type_to_sql(:integer, 4) => "int(11)" ActiveRecord::Base.connection.type_to_sql(:integer, 8) => "bigint"
-
Hugo Peixoto August 8th, 2009 @ 10:54 PM
In mysql, I'm able to create a table with int(20):
mysql> create table test(id int(20)); mysql> show columns from test; +-------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+---------+------+-----+---------+-------+ | id | int(20) | YES | | NULL | | +-------+---------+------+-----+---------+-------+
If I insert large values (like 9999999999999999999) they won't be saved.
mysql> insert into test VALUES (9999999999999999999); mysql> select id from test; +------------+ | id | +------------+ | 2147483647 | +------------+ 1 row in set (0.00 sec)
int(20) only does something if you use it in conjunction with ZEROFILL,
in which the mysql interactive tools will print out something like this:mysql> drop table test; mysql> create table test(id int(20) zerofill); mysql> insert into test VALUES (9999999999999999999); mysql> select id from test; +----------------------+ | id | +----------------------+ | 00000000004294967295 | +----------------------+
Odd behaviour, but since it doesn't change the storage size, I'd say it's irrelevant for rails purpose. I say +1 for closing this ticket.
-
CancelProfileIsBroken August 9th, 2009 @ 03:21 PM
- Tag changed from 2.2.2, activerecord, bugmash, limit, schema to 2.2.2, activerecord, limit, schema
- State changed from new to invalid
Not worth changing Rails core unless we see some use case and patch that isn't mysql-specific.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>