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.
Tarmo Tänav (author)
Sat Aug 23 09:51:09 -0700 2008
commit  74c3c701f73407a5bb1a11be2b5b221fe39895d3
tree    995e5671c3b99b161b4a65e11657fc946acbc02b
parent  5232d812819d1d44187a54cb025835b1f9cb2296
...
384
385
386
387
388
389
390
391
392
 
 
393
394
395
...
384
385
386
 
 
 
 
 
 
387
388
389
390
391
0
@@ -384,12 +384,8 @@ module ActiveRecord
0
       def add_column_options!(sql, options) #:nodoc:
0
         sql << " DEFAULT #{quote(options[:default], options[:column])}" if options_include_default?(options)
0
         # must explicitly 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
+        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