public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Don't set "NULL" as a constraint on nullable columns [#398 state:resolved]

This is already the default and adding it breaks SQL standards compatibility.

Conflicts:

  
  activerecord/lib/active_record/connection_adapters/abstract/schema_statements.
  rb
Tarmo Tänav (author)
Sat Aug 23 19:57:33 -0700 2008
commit  ddb8c9c92ed09d33ae573891a4ef0d566622f317
tree    09b0f1bd8c8c8d73b4049b27fa4b7c879998ada3
parent  482e8fe62a58fb2b56875cea13d082bd09b3f228
...
383
384
385
386
387
388
389
390
391
392
 
 
 
393
394
395
...
383
384
385
 
 
 
 
 
 
 
386
387
388
389
390
391
0
@@ -383,13 +383,9 @@ module ActiveRecord
0
 
0
       def add_column_options!(sql, options) #:nodoc:
0
         sql << " DEFAULT #{quote(options[:default], options[:column])}" if options_include_default?(options)
0
-        # must explcitly check for :null to allow change_column to work on migrations
0
-        if options.has_key? :null
0
-          if options[:null] == false
0
-            sql << " NOT NULL"
0
-          else
0
-            sql << " NULL"
0
-          end
0
+        # must explicitly check for :null to allow change_column to work on migrations
0
+        if options[:null] == false
0
+          sql << " NOT NULL"
0
         end
0
       end
0
 
...
9
10
11
12
 
13
14
15
16
17
18
 
19
20
21
...
23
24
25
26
 
27
28
29
...
33
34
35
36
37
 
...
9
10
11
 
12
13
14
15
16
17
 
18
19
20
21
...
23
24
25
 
26
27
28
29
...
33
34
35
 
36
37
0
@@ -9,13 +9,13 @@ class ColumnDefinitionTest < ActiveRecord::TestCase
0
   end
0
 
0
   # Avoid column definitions in create table statements like:
0
-  # `title` varchar(255) DEFAULT NULL NULL
0
+  # `title` varchar(255) DEFAULT NULL
0
   def test_should_not_include_default_clause_when_default_is_null
0
     column = ActiveRecord::ConnectionAdapters::Column.new("title", nil, "varchar(20)")
0
     column_def = ActiveRecord::ConnectionAdapters::ColumnDefinition.new(
0
       @adapter, column.name, "string",
0
       column.limit, column.precision, column.scale, column.default, column.null)
0
-    assert_equal "title varchar(20) NULL", column_def.to_sql
0
+    assert_equal "title varchar(20)", column_def.to_sql
0
   end
0
 
0
   def test_should_include_default_clause_when_default_is_present
0
@@ -23,7 +23,7 @@ class ColumnDefinitionTest < ActiveRecord::TestCase
0
     column_def = ActiveRecord::ConnectionAdapters::ColumnDefinition.new(
0
       @adapter, column.name, "string",
0
       column.limit, column.precision, column.scale, column.default, column.null)
0
-    assert_equal %Q{title varchar(20) DEFAULT 'Hello' NULL}, column_def.to_sql
0
+    assert_equal %Q{title varchar(20) DEFAULT 'Hello'}, column_def.to_sql
0
   end
0
 
0
   def test_should_specify_not_null_if_null_option_is_false
0
@@ -33,4 +33,4 @@ class ColumnDefinitionTest < ActiveRecord::TestCase
0
       column.limit, column.precision, column.scale, column.default, column.null)
0
     assert_equal %Q{title varchar(20) DEFAULT 'Hello' NOT NULL}, column_def.to_sql
0
   end
0
-end
0
\ No newline at end of file
0
+end

Comments