mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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.
This commit is contained in:
parent
5232d81281
commit
74c3c701f7
2 changed files with 6 additions and 10 deletions
|
@ -384,12 +384,8 @@ module ActiveRecord
|
|||
def add_column_options!(sql, options) #:nodoc:
|
||||
sql << " DEFAULT #{quote(options[:default], options[:column])}" if options_include_default?(options)
|
||||
# must explicitly check for :null to allow change_column to work on migrations
|
||||
if options.has_key? :null
|
||||
if options[:null] == false
|
||||
sql << " NOT NULL"
|
||||
else
|
||||
sql << " NULL"
|
||||
end
|
||||
if options[:null] == false
|
||||
sql << " NOT NULL"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -9,13 +9,13 @@ class ColumnDefinitionTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
# Avoid column definitions in create table statements like:
|
||||
# `title` varchar(255) DEFAULT NULL NULL
|
||||
# `title` varchar(255) DEFAULT NULL
|
||||
def test_should_not_include_default_clause_when_default_is_null
|
||||
column = ActiveRecord::ConnectionAdapters::Column.new("title", nil, "varchar(20)")
|
||||
column_def = ActiveRecord::ConnectionAdapters::ColumnDefinition.new(
|
||||
@adapter, column.name, "string",
|
||||
column.limit, column.precision, column.scale, column.default, column.null)
|
||||
assert_equal "title varchar(20) NULL", column_def.to_sql
|
||||
assert_equal "title varchar(20)", column_def.to_sql
|
||||
end
|
||||
|
||||
def test_should_include_default_clause_when_default_is_present
|
||||
|
@ -23,7 +23,7 @@ class ColumnDefinitionTest < ActiveRecord::TestCase
|
|||
column_def = ActiveRecord::ConnectionAdapters::ColumnDefinition.new(
|
||||
@adapter, column.name, "string",
|
||||
column.limit, column.precision, column.scale, column.default, column.null)
|
||||
assert_equal %Q{title varchar(20) DEFAULT 'Hello' NULL}, column_def.to_sql
|
||||
assert_equal %Q{title varchar(20) DEFAULT 'Hello'}, column_def.to_sql
|
||||
end
|
||||
|
||||
def test_should_specify_not_null_if_null_option_is_false
|
||||
|
@ -33,4 +33,4 @@ class ColumnDefinitionTest < ActiveRecord::TestCase
|
|||
column.limit, column.precision, column.scale, column.default, column.null)
|
||||
assert_equal %Q{title varchar(20) DEFAULT 'Hello' NOT NULL}, column_def.to_sql
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue