I'm trying to make a little financial game with phalcon. I want create a table which contains start money amount for each player. My code looks like this:
$db->createTable(
"start_money",null,
array(
"columns" => array(
new Column(
"id",
array(
"type" => Column::TYPE_INTEGER,
"size" => 10,
"unsigned" => true,
"notNull" => true,
"autoIncrement" => true,
"first" => true,
)
),
new Column(
"amount",
array(
"type" => Column::TYPE_INTEGER,
"size" => 10,
"unsigned" => true,
"notNull" => true,
)
),
new Column(
"condition_id",
array(
"type" => Column::TYPE_INTEGER,
"size" => 10,
"unsigned" => true,
)
),
),
"indexes" => array(
new Index(
"PRIMARY",
array("id")
),
new Index(
"condition_id",
array("condition_id")
)
),
"references" => array(
new Reference(
"start_money_condition_id",
array(
"referencedTable" => "start_conditions",
"columns" => array("condition_id"),
"referencedColumns" => array("id"),
)
)
),
"options" => array(
"TABLE_TYPE" => "BASE TABLE",
"ENGINE" => "InnoDB",
"TABLE_COLLATION" => "utf8_general_ci",
)
)
);
Then I type 'show create table start_money' into mysql console and i see:
start_money | CREATE TABLE `start_money` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`amount` int(10) unsigned NOT NULL,
`condition_id` int(10) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `condition_id` (`condition_id`),
CONSTRAINT `start_money_condition_id` FOREIGN KEY (`id`) REFERENCES `start_conditions` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
My foreign key column is 'id', not 'condition_id'. I can't save any data because of this problem. Sorry for my bad english.