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

Ticket #6956 (closed defect: fixed)

Opened 2 years ago

Last modified 2 years ago

[PATCH] cannot change column default to NULL

Reported by: dcmanges Assigned to: nzkoz
Priority: normal Milestone: 1.x
Component: ActiveRecord Version: edge
Severity: normal Keywords: change_column migrations
Cc:

Description (Last modified by nzkoz)

With MySQL:

>> ActiveRecord::Schema.define do
?> create_table :people do |t|
?> t.column :name, :string, :default => 'Dan Manges'
>> end
>> end

SQL: CREATE TABLE people (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `name` varchar(255) DEFAULT 'Dan Manges') ENGINE=InnoDB

>> ActiveRecord::Schema.define do
?> change_column :people, :name, :string, :default => nil
>> end

SQL: ALTER TABLE people CHANGE name name varchar(255) DEFAULT 'Dan Manges'

This is due to checking for the default value with: if options[:default]

Attachments

change_column_default_to_null.diff (5.4 kB) - added by dcmanges on 01/09/07 06:17:15.
includes tests

Change History

01/09/07 06:17:15 changed by dcmanges

  • attachment change_column_default_to_null.diff added.

includes tests

01/09/07 06:19:07 changed by dcmanges

The following adapters are patched:

sqlserver_adapter.rb mysql_adapter.rb postgresql_adapter.rb frontbase_adapter.rb sqlite_adapter.rb

However, I only ran tests on MySQL. Could somebody run the tests on the other adapters?

01/09/07 06:48:47 changed by nzkoz

  • owner changed from core to nzkoz.
  • status changed from new to assigned.

01/09/07 06:50:27 changed by nzkoz

  • description changed.

fixing formatting

01/09/07 11:05:28 changed by jonathan_viney

Also see #6664

01/15/07 02:22:54 changed by bitsweat

  • status changed from assigned to closed.
  • resolution set to fixed.

(In [5937]) change_column accepts :default => nil. Closes #6956.

01/15/07 02:26:06 changed by bitsweat

(In [5938]) Merge [5937] from trunk. References #6956.