mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Migrations will raise an exception if there are multiple column definitions (same name).
This commit is contained in:
parent
c1844477a1
commit
7ef9849e3d
3 changed files with 23 additions and 2 deletions
|
@ -1,3 +1,9 @@
|
|||
* Migrations raise when duplicate column definition.
|
||||
|
||||
Fixes #33024.
|
||||
|
||||
*Federico Martinez*
|
||||
|
||||
* Bump minimum SQLite version to 3.8
|
||||
|
||||
*Yasuo Honda*
|
||||
|
|
|
@ -356,8 +356,12 @@ module ActiveRecord
|
|||
type = type.to_sym if type
|
||||
options = options.dup
|
||||
|
||||
if @columns_hash[name] && @columns_hash[name].primary_key?
|
||||
raise ArgumentError, "you can't redefine the primary key column '#{name}'. To define a custom primary key, pass { id: false } to create_table."
|
||||
if @columns_hash[name]
|
||||
if @columns_hash[name].primary_key?
|
||||
raise ArgumentError, "you can't redefine the primary key column '#{name}'. To define a custom primary key, pass { id: false } to create_table."
|
||||
else
|
||||
raise ArgumentError, "you can't define an already defined column '#{name}'."
|
||||
end
|
||||
end
|
||||
|
||||
index_options = options.delete(:index)
|
||||
|
|
|
@ -196,6 +196,17 @@ module ActiveRecord
|
|||
assert_equal "you can't redefine the primary key column 'testing_id'. To define a custom primary key, pass { id: false } to create_table.", error.message
|
||||
end
|
||||
|
||||
def test_create_table_raises_when_defining_existing_column
|
||||
error = assert_raise(ArgumentError) do
|
||||
connection.create_table :testings do |t|
|
||||
t.column :testing_column, :string
|
||||
t.column :testing_column, :integer
|
||||
end
|
||||
end
|
||||
|
||||
assert_equal "you can't define an already defined column 'testing_column'.", error.message
|
||||
end
|
||||
|
||||
def test_create_table_with_timestamps_should_create_datetime_columns
|
||||
connection.create_table table_name do |t|
|
||||
t.timestamps
|
||||
|
|
Loading…
Reference in a new issue