Permalink
Browse files

Don't carry default value when changing column for a binary type on M…

…ySQL [#3234 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent 0706bdc commit ddadcc7cf8332415ba48b66904ee6136b43dda6b Elomar França committed with josevalim Sep 27, 2009
@@ -506,7 +506,7 @@ def change_column_null(table_name, column_name, null, default = nil)
def change_column(table_name, column_name, type, options = {}) #:nodoc:
column = column_for(table_name, column_name)
- unless options_include_default?(options)
+ if has_default?(type) && !options_include_default?(options)
options[:default] = column.default
end
@@ -655,6 +655,10 @@ def column_for(table_name, column_name)
end
column
end
+
+ def has_default?(sql_type)
+ sql_type =~ :binary || sql_type == :text #mysql forbids defaults on blob and text columns
+ end
end
end
end
@@ -823,6 +823,16 @@ def test_change_column_default
assert_equal "Tester", Person.new.first_name
end
+ def test_change_column_type_default_should_change
+ old_columns = Person.connection.columns(Person.table_name, "#{name} Columns")
+ assert !old_columns.find { |c| c.name == 'data' }
+
+ assert_nothing_raised do
+ Person.connection.add_column "people", "data", :string, :default => ''
+ Person.connection.change_column "people", "data", :binary
+ end
+ end
+
def test_change_column_quotes_column_names
Person.connection.create_table :testings do |t|
t.column :select, :string

0 comments on commit ddadcc7

Please sign in to comment.