Remove default integer :limit from MysqlAdapter.native_database_types
Reported by matthuhiggins | April 27th, 2008 @ 05:11 PM
A recent change to the MySql adapter adds smallint and bigint support based on the specified :limit. Since the default integer limit is specified as 11, integer columns now default with type 'bigint(11)' rather than 'int(11)'. I assume this change was unintentional.
Patch is attached.
Comments and changes to this ticket
-

david (at loudthinking) April 29th, 2008 @ 04:48 PM
- → State changed from new to resolved
Closed by http://github.com/rails/rails/co...
-

Mirko Froehlich May 21st, 2008 @ 03:39 PM
- → Assigned user changed from to david (at loudthinking)
Actually this does not seem to be fixed. I am running into this issue as well:
When I run "rake db:test:clone" in Rails 2.0.991, it now creates foreign key integer columns as bigint(11) rather than int(11), which later causes problems for our foreign key constraints since the types don't match those of the primary keys.
Could it be that it infers the limit of 11 from my development database (even though my migrations don't explicitly specify a limit), and then applies this when cloning the test database, thus creating these columns as bigint instead of int?
-

Mirko Froehlich May 21st, 2008 @ 04:57 PM
I am now convinced that this is the problem, i.e. rake db:test:clone results in integer columns that were originally created without an explicit limit in the migration script (and implicitly ended up as int(11)) to be created as bigint(11) in the test db, rendering them incompatible with primary keys of type int(11). This would never cause a problem in production or development, but it breaks the tests if you are using foreign key constraints.
I am not sure about a good solution, other than reverting the bigint change. For my purposes, I am currently monkey-patching this code to raise the bigint range from 9..20 to 12..20, which bypasses this problem.
-

Bill Cleveland July 3rd, 2008 @ 02:49 PM
- → Tag changed from to activerecord patch
Can we patch the mysql_adapter so that the primary index is a bigint(11) instead of a int(11)?
This would solve the following problems:
1. The 11 in int(11) is a formatting specification and not a datatype specification. Therefore even though we specified an integer being formatted to display 11 character wide, the key value can only store 9 digits (well 9 full digits) due to the index being only 32 bits wide.
2. The issue that Mirko is having would be resolved, since the foreign key integer columns would now correctly match the data type of the primary key.
3. Being a BIGINT the primary key data type inches closer to the standard data type that MySQL databases use as its primary key which is an UNSIGNED BIGINT
Thanks,
Bill
-

Bill Cleveland July 3rd, 2008 @ 03:30 PM
- → Tag cleared.
Well since there is a move to change the interpretation of :limit to number of bytes instead of number of characters, please disregard some of my previous comment.
It would be nice if the primary_key was created using a "key datatype" like :uid, so that regardless of which database adapter is being used, it will be possible to create foreign_key columns with the same datatype as the primary key it references.
I would still like the MySQL adapter to use BIGINT as its primary key.
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
Source available from github
The Git repository resides at http://github.com/rails
Check out the current development trunk (Edge Rails) with:
git clone git://github.com/rails/rails.git
The latest development for the 1.2.x and 2.0.x releases are on the 1-2-stable and 2-0-stable branches.
Creating a bug report
When creating a bug report, be sure to include as much relevant information as possible. Post the code sample that causes the problem. Preferably, alter the unit tests and show through either changed or added tests how the expected behavior is not occuring.
Security vulnerabilities should be reported via an email to security@rubyonrails.org, do not use trac for reporting security vulnerabilities. All content in trac is publicly available as soon as it is posted.
Then don't get your hopes up. Unless you have a "Code Red, Mission Critical, The World is Coming to an End" kinda bug, you're creating this ticket in the hope that others with the same problem will be able to collaborate with you on solving it. Do not expect that the ticket automatically will see any activity or that others will jump to fix it. Creating a ticket like this is mostly to help yourself start on the path of fixing the problem and for others to sign on to with a "I'm having this problem too".
