This project is archived and is in readonly mode.
rename_column doesn't preserve default value on MySQL
Reported by Diego Algorta | June 22nd, 2008 @ 12:47 AM
migration 1
create_table "users", :force => true do |t| t.column :name, :string, :default => '' end
migration 2
rename_column :users, :name, :first_name
result: the column first_name doesn't have the default value anymore.
I'm attaching a patch including a test for this issue.
Comments and changes to this ticket
-
Jeremy Kemper June 22nd, 2008 @ 12:59 AM
- Milestone set to 2.1.1
- Assigned user set to Jeremy Kemper
- State changed from new to open
Talked about this in #rails-contrib:
- should raise ActiveRecordError instead of RuntimeError, and add a test for rename_column with a column that does not exist
- and test that a column with DEFAULT NULL is preserved also
-
Diego Algorta June 22nd, 2008 @ 03:38 AM
Here's a new version of the patch. This one adds a new test for renaming nonexistent columns and raises ActiveRecordError in that case.
I realized the "unless default.nil?" was unnecessary so the extra test for that is unnecessary too. Because DEFAULT NULL is the default anyway. So using :default => nil is the same as not using it.
I squashed the changes into only one commit.
-
Diego Algorta June 22nd, 2008 @ 03:42 AM
I mean... I DID add the test for the DEFAULT NULL case... but the current and the new code already passed that. So I thought it was unnecessary.
-
Repository June 22nd, 2008 @ 11:23 PM
- State changed from open to resolved
(from [2e1b56c93745bf0513e449e95830edd390abfaf2]) MySQL: rename_column preserves default values. [#466 state:resolved]
-
Repository June 22nd, 2008 @ 11:23 PM
(from [9855d0b0800d92626aa19606628ed77042491984]) MySQL: rename_column preserves default values. [#466 state:resolved]
-
Rick October 31st, 2008 @ 03:38 AM
- Assigned user cleared.
- Milestone cleared.
- Tag set to 2.1, activerecord, bug, edge, patch, tested
Testing...
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>