Hi
I’m new to Rails. This is my first application and I’m trying to set
up a schema I’ve hand-crafted as a migration.
Does anybody know why this…
# deposit_types
create_table :deposit_types do |table|
table.column :type_code, :string, :limit => 20, :null => false
table.column :description, :string, :limit => 50, :null => false
end
add_index :deposit_types, :type_code, :unique
add_index :deposit_types, :description, :unique
[ ["pc_of_tcp", "percentage of total cash price"],
["amount", "amount"],
["payments", "payments"] ].each do |type, description|
DepositType.create :type_code => type, :description =>
description
end
works, but this…
# deposit_types
create_table :deposit_types do |table|
table.column :type, :string, :limit => 20, :null => false
table.column :description, :string, :limit => 50, :null => false
end
add_index :deposit_types, :type, :unique
add_index :deposit_types, :description, :unique
[ ["pc_of_tcp", "percentage of total cash price"],
["amount", "amount"],
["payments", "payments"] ].each do |type, description|
DepositType.create :type => type, :description => description
end
(note change of type_code to type)
The second migration fails because it tries to insert NULL into the
type column:
PGError: ERROR: null value in column “type” violates not-null
constraint
: INSERT INTO deposit_types (“type”, “description”) VALUES(NULL,
‘percentage of total cash price’)
I haven’t gone through the ActiveRecord code to see what’s going on.
Is this a known gotcha? Is :type special somehow? I’ll stick with
type_code for now.
Thanks
Ashley