How to get Rails to generate 'schema.rb' with bigint support for MySQL?

I am using Rails 3.0.5. I use MySQL as a database repository. I have a model in which one of the columns must be BIGINT. In my migration creation file, I use the following:

t.column :my_column_name, :bigint 

which works great.

However, when I run

rake db: migrate

the generated schema.rb file creates the following line for a specific column:

 t.integer "my_column_name", :limit => 8 

which is wrong.

My question is where am I mistaken? Is there something I have to do to get the correct schema.rb file? Can I change the way the schema.rb file is created?

Please note that the fact that the "schema.rb" file is incorrect causes problems on my continuous integration server, which runs tests and creates db from scratch (before running the tests) using the "schema.rb" file.

+6
mysql ruby-on-rails bigint
source share
1 answer

Now I understand that

 t.integer "my_column_name", :limit => 8 

with the driver my_sql is CORRECT in the schema.rb file.

The database generated using the schema.rb file creates

 bigint(20) 

although this may seem odd.

I found this by examining the adapter code my_sql, a fragment of which I quote here:

  def type_to_sql(type, limit = nil, precision = nil, scale = nil) return super unless type.to_s == 'integer' case limit when 1; 'tinyint' when 2; 'smallint' when 3; 'mediumint' when nil, 4, 11; 'int(11)' # compatibility with MySQL default when 5..8; 'bigint' else raise(ActiveRecordError, "No integer type has byte size #{limit}") end end 

It is clear that: limit => 8 will complete the creation of bigint in mysql db.

+9
source share

All Articles