Hi,
I’ve set up a model as follows
class EquipmentPrice < ActiveRecord::Base
acts_as_tree :order => “id”
…
end
which has the following db migration
class CreateEquipmentPrices < ActiveRecord::Migration
def self.up
create_table :equipment_prices do |t|
t.integer :id
t.string :manufacturer
t.string :model
t.string :equipment_type
t.integer :capacity
t.integer :string_size
t.string :cost_structure
t.string :currency
t.decimal :price_each
t.decimal :price_bulk
t.integer :bulk_quantity
t.integer :parent_id
t.timestamps
end
end
def self.down
drop_table :equipment_prices
end
end
But when I try and run the default test, I get an error message
stating
ActiveRecord::StatementInvalid: Mysql::Error: Duplicate entry ‘1’ for
key 1: INSERT INTO equipment_prices
(id
, manufacturer
, model
,
equipment_type
, capacity
, string_size
, cost_structure
,
currency
, price_each
, price_bulk
, bulk_quantity
, parent_id
,
created_at
, updated_at
) VALUES (1, NULL, NULL, ‘PV_subsystem’,
NULL, NULL, NULL, ‘USD’, 0.0, 0.0, 1, 0, ‘2010-03-11 12:14:05’,
‘2010-03-11 12:14:05’)
I have read in an earlier post that this is because I have parent_id
set as the primary key for the table. But when I look at the mysql
table definition I see
mysql> describe equipment_prices;
±---------------±--------------±-----±----±--------
±---------------+
| Field | Type | Null | Key | Default |
Extra |
±---------------±--------------±-----±----±--------
±---------------+
| id | int(11) | NO | PRI | NULL |
auto_increment |
| manufacturer | varchar(255) | YES | | NULL
| |
| model | varchar(255) | YES | | NULL
| |
| equipment_type | varchar(255) | YES | | NULL
| |
| capacity | int(11) | YES | | NULL
| |
| string_size | int(11) | YES | | NULL
| |
| cost_structure | varchar(255) | YES | | NULL
| |
| currency | varchar(255) | YES | | NULL
| |
| price_each | decimal(10,0) | YES | | NULL
| |
| price_bulk | decimal(10,0) | YES | | NULL
| |
| bulk_quantity | int(11) | YES | | NULL
| |
| parent_id | int(11) | YES | | NULL
| |
| created_at | datetime | YES | | NULL
| |
| updated_at | datetime | YES | | NULL
| |
±---------------±--------------±-----±----±--------
±---------------+
14 rows in set (0.00 sec)
which appears to show that id is the primary key, as I would expect.
What am I doing wrong here please?
Thanks
Steve