Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

rename_column doesn't preserve default value on MySQL

#466

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.

Reported by Diego Algorta · June 22nd, 2008 @ 12:47 AM

State: resolved
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Jeremy Kemper
    Jeremy Kemper
    • 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

    June 22nd, 2008 @ 12:59 AM

  2. Diego Algorta
    Diego Algorta

    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.

    June 22nd, 2008 @ 03:38 AM

  3. Diego Algorta
    Diego Algorta

    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.

    June 22nd, 2008 @ 03:42 AM

  4. Diego Algorta
  5. Repository
    Repository
    • State changed from open to resolved

    (from [2e1b56c93745bf0513e449e95830edd390abfaf2]) MySQL: rename_column preserves default values. [#466 state:resolved]

    http://github.com/rails/rails/co...

    June 22nd, 2008 @ 11:23 PM

  6. Repository
    Repository

    (from [9855d0b0800d92626aa19606628ed77042491984]) MySQL: rename_column preserves default values. [#466 state:resolved]

    http://github.com/rails/rails/co...

    June 22nd, 2008 @ 11:23 PM

  7. Rick
    Rick
    • Assigned user cleared.
    • Milestone cleared.
    • Tag set to 2.1, activerecord, bug, edge, patch, tested

    Testing...

    October 31st, 2008 @ 03:38 AM