Skip to content
This repository
Browse code

MySQL: fix change_column on not-null columns that don't accept dfeaul…

…t values of ''. Closes #6663.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7790 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 85c86f09997fff1f07f5d58ecf69780d597e292c 1 parent b1e394e
Jeremy Kemper authored October 08, 2007
2  activerecord/CHANGELOG
... ...
@@ -1,5 +1,7 @@
1 1
 *SVN*
2 2
 
  3
+* MySQL: fix change_column on not-null columns that don't accept dfeault values of ''.  #6663 [Jonathan Viney, Tarmo Tänav]
  4
+
3 5
 * validates_uniqueness_of behaves well with single-table inheritance.  #3833 [Gabriel Gironda, rramdas, François Beausoleil, Josh Peek, Tarmo Tänav]
4 6
 
5 7
 * Raise ProtectedAttributeAssignmentError in development and test environments when mass-assigning to an attr_protected attribute.  #9802 [Henrik N]
4  activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -408,8 +408,8 @@ def change_column_default(table_name, column_name, default) #:nodoc:
408 408
 
409 409
       def change_column(table_name, column_name, type, options = {}) #:nodoc:
410 410
         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
413 413
           else
414 414
             raise "No such column: #{table_name}.#{column_name}"
415 415
           end
10  activerecord/test/migration_test.rb
@@ -429,6 +429,16 @@ def test_rename_column_with_sql_reserved_word
429 429
         Person.connection.add_column("people", "first_name", :string) rescue nil
430 430
       end
431 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
  440
+      end
  441
+    end
432 442
 
433 443
     def test_rename_table
434 444
       begin

0 notes on commit 85c86f0

Please sign in to comment.
Something went wrong with that request. Please try again.