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

Ticket #8103 (closed defect: duplicate)

Opened 2 years ago

Last modified 5 months ago

[PATCH] [TEST] change_column_default loses NOT NULL setting in MySQL and SQL Server

Reported by: bigo Assigned to: core
Priority: normal Milestone: 2.x
Component: ActiveRecord Version: 1.2.3
Severity: minor Keywords: patch, test, migrations, change_column_default
Cc:

Description

A column that previously had NOT NULL set will lose it (become NULLable) when running a change_column_default migration on that column, in MySQL at least. The last set of enhancements to this method neglected to test this particular attribute.

As soon as I figure out how, I'll even submit the patch :p woo first defect.

Attachments

test_change_column_default.diff (5.0 kB) - added by lawrence on 10/22/07 22:54:15.

Change History

06/27/07 00:32:53 changed by matt

same problem with postgresql see #8115

09/17/07 21:45:07 changed by lawrence

* when using change_column_default MySQL lost its NOT NULL definition * when using rename_column MySQL lost its NOT NULL definition /and/ its DEFAULT definition.

Attached is a patch for this, including a unit test.

Also tested for SQL Server. Two extra issues solved: * when using add_column for SQL Server with :null=>false but no default specified it fails. It now adds a default DEFAULT clause for this case. * when using change_column for SQL Server it did not take a NOT NULL definition (:null=>false) into account.

09/17/07 21:57:08 changed by lawrence

  • summary changed from change_column_default loses NOT NULL setting in MySQL to [PATCH] change_column_default loses NOT NULL setting in MySQL.

10/22/07 02:18:34 changed by lawrence

  • keywords changed from migrations, change_column_default to patch, test, migrations, change_column_default.
  • summary changed from [PATCH] change_column_default loses NOT NULL setting in MySQL to [PATCH] [TEST] change_column_default loses NOT NULL setting in MySQL and SQL Server.

10/22/07 02:20:24 changed by lawrence

(In [7987]) SQLServer: fix for change_column_default, which lost NOT NULL setting. References #8103

10/22/07 22:54:15 changed by lawrence

  • attachment test_change_column_default.diff added.

10/22/07 23:36:53 changed by bitsweat

Looks good, but

+      assert_raises(ActiveRecord::StatementInvalid) {Person.connection.execute("update testings set wealth = NULL")}

fails on MySQL 5.1 with strict mode off, for me.

Has anyone else tested this out?

07/14/08 18:11:11 changed by bitsweat

  • status changed from new to closed.
  • resolution set to duplicate.