diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-10-08 03:28:28 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-10-08 03:28:28 +0000 |
commit | 85c86f09997fff1f07f5d58ecf69780d597e292c (patch) | |
tree | b604f3ae483faef737b9779cc1f8f29e685cb1d8 /activerecord | |
parent | b1e394e67f0b079335c936b6b120b92f00a244c5 (diff) | |
download | rails-85c86f09997fff1f07f5d58ecf69780d597e292c.tar.gz rails-85c86f09997fff1f07f5d58ecf69780d597e292c.tar.bz2 rails-85c86f09997fff1f07f5d58ecf69780d597e292c.zip |
MySQL: fix change_column on not-null columns that don't accept dfeault values of ''. Closes #6663.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7790 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rwxr-xr-x | activerecord/lib/active_record/connection_adapters/mysql_adapter.rb | 4 | ||||
-rw-r--r-- | activerecord/test/migration_test.rb | 10 |
3 files changed, 14 insertions, 2 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index befb440765..2c1f8d7bd9 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* MySQL: fix change_column on not-null columns that don't accept dfeault values of ''. #6663 [Jonathan Viney, Tarmo Tänav] + * validates_uniqueness_of behaves well with single-table inheritance. #3833 [Gabriel Gironda, rramdas, François Beausoleil, Josh Peek, Tarmo Tänav] * Raise ProtectedAttributeAssignmentError in development and test environments when mass-assigning to an attr_protected attribute. #9802 [Henrik N] diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb index f0d6e443a7..62cfc345a3 100755 --- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb @@ -408,8 +408,8 @@ module ActiveRecord def change_column(table_name, column_name, type, options = {}) #:nodoc: unless options_include_default?(options) - if result = select_one("SHOW COLUMNS FROM #{table_name} LIKE '#{column_name}'") - options[:default] = result['Default'] + if column = columns(table_name).find { |c| c.name == column_name.to_s } + options[:default] = column.default else raise "No such column: #{table_name}.#{column_name}" end diff --git a/activerecord/test/migration_test.rb b/activerecord/test/migration_test.rb index a1eda28aa4..13c9dc692a 100644 --- a/activerecord/test/migration_test.rb +++ b/activerecord/test/migration_test.rb @@ -429,6 +429,16 @@ if ActiveRecord::Base.connection.supports_migrations? Person.connection.add_column("people", "first_name", :string) rescue nil end end + + def test_change_type_of_not_null_column + assert_nothing_raised do + Topic.connection.change_column "topics", "written_on", :datetime, :null => false + Topic.reset_column_information + + Topic.connection.change_column "topics", "written_on", :datetime, :null => false + Topic.reset_column_information + end + end def test_rename_table begin |