I have created a migration using migrate create and put following codes on it:
<?php
class m131220_121449_create_all_tables extends CDbMigration
{
// Use safeUp/safeDown to do migration with transaction
public function safeUp() {
// MEMBERS TABLE
$this->createTable("members", array(
'uniq_id' => 'pk',
'personel_num' => 'int(10) NOT NULL',
'password' => 'string NOT NULL',
'name' => 'string DEFAULT NULL',
'lastupdate' => 'timestamp DEFAULT CURRENT_TIMESTAMP',
), 'ENGINE=InnoDB');
// RESERVED TABLE
$this->createTable("reserved", array(
'uniq_id' => 'pk',
'personel_num' => 'int(10) NOT NULL',
'RsvdDay' => 'date NOT NULL',
'date_created' => 'timestamp DEFAULT CURRENT_TIMESTAMP',
), 'ENGINE=InnoDB');
// Add Foreign Keys Relations for RESERVED
$this->addForeignKey("fk_rsvd_user", "reserved", "personel_num", "members", "personel_num", "CASCADE", "RESTRICT");
}
}
But when I want to up this migration I got General Error #1005 when it tries to create Foreign Keys.
The image of the error has been attached.