mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Don't carry default value when changing column for a binary type on MySQL [#3234 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
parent
3afdfc35e8
commit
edec1afe25
2 changed files with 15 additions and 1 deletions
|
@ -513,7 +513,7 @@ module ActiveRecord
|
|||
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
|
||||
|
||||
|
@ -675,6 +675,10 @@ module ActiveRecord
|
|||
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
|
||||
|
|
|
@ -860,6 +860,16 @@ if ActiveRecord::Base.connection.supports_migrations?
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue