Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 7790

Show
Ignore:
Timestamp:
10/08/07 03:28:28 (1 year ago)
Author:
bitsweat
Message:

MySQL: fix change_column on not-null columns that don't accept dfeault values of . Closes #6663.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/CHANGELOG

    r7787 r7790  
    11*SVN* 
     2 
     3* MySQL: fix change_column on not-null columns that don't accept dfeault values of ''.  #6663 [Jonathan Viney, Tarmo TÀnav] 
    24 
    35* validates_uniqueness_of behaves well with single-table inheritance.  #3833 [Gabriel Gironda, rramdas, François Beausoleil, Josh Peek, Tarmo TÀnav] 
  • trunk/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb

    r7780 r7790  
    409409      def change_column(table_name, column_name, type, options = {}) #:nodoc: 
    410410        unless options_include_default?(options) 
    411           if result = select_one("SHOW COLUMNS FROM #{table_name} LIKE '#{column_name}'") 
    412             options[:default] = result['Default'] 
     411          if column = columns(table_name).find { |c| c.name == column_name.to_s } 
     412            options[:default] = column.default 
    413413          else 
    414414            raise "No such column: #{table_name}.#{column_name}" 
  • trunk/activerecord/test/migration_test.rb

    r7766 r7790  
    428428        Person.connection.remove_column("people", "group") rescue nil 
    429429        Person.connection.add_column("people", "first_name", :string) rescue nil 
     430      end 
     431    end 
     432     
     433    def test_change_type_of_not_null_column 
     434      assert_nothing_raised do 
     435        Topic.connection.change_column "topics", "written_on", :datetime, :null => false 
     436        Topic.reset_column_information 
     437         
     438        Topic.connection.change_column "topics", "written_on", :datetime, :null => false 
     439        Topic.reset_column_information 
    430440      end 
    431441    end