0

我有迁移:

功能向上:

$this->createTable(
            'vacancy_moderate',
            array(
                'id' => 'int(10) unsigned NOT NULL AUTO_INCREMENT',
                'period_days' => 'tinyint(4) NOT NULL',
                'title' => 'varchar(255) NOT NULL DEFAULT \'\'',
                'price'=> 'int(11) DEFAULT NULL',
                'requirements'=> 'text NOT NULL',
                'conditions'=> 'text',
                'contact_details'=> 'text NOT NULL',
                'country_id'=> 'int(10) unsigned NOT NULL',
                'city_id'=> 'int(10) unsigned DEFAULT NULL',
                'user_id'=> 'int(10) unsigned DEFAULT NULL',
                'club_id'=> 'int(10) DEFAULT NULL',
                'PRIMARY KEY (`id`)',
                'KEY `city_id` (`city_id`)',
                'KEY `user_id` (`user_id`)',
                'KEY `country_id` (`country_id`)',
                'KEY `club_id` (`club_id`)',
                'CONSTRAINT `vacancy_moderate_ibfk_1` FOREIGN KEY (`city_id`) REFERENCES `city` (`id`) ON UPDATE CASCADE',
                'CONSTRAINT `vacancy_moderate_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE',
                'CONSTRAINT `vacancy_moderate_ibfk_3` FOREIGN KEY (`country_id`) REFERENCES `country` (`id`) ON UPDATE CASCADE',
                'CONSTRAINT `vacancy_moderate_ibfk_4` FOREIGN KEY (`club_id`) REFERENCES `clubs` (`id`) ON UPDATE CASCADE'
            ),
            'ENGINE=InnoDB DEFAULT CHARSET=utf8'
        );

功能向下:

$this->dropTable('vacancy_moderate');

问题: 我应该手动删除所有外键还是将它们删除到 dropTable 中?

4

2 回答 2

1

他们会和桌子一起掉下来,因为一切都会过去。:-)

于 2013-07-11T12:33:51.017 回答
0

Yii dropTable() 函数仅仅调用 MySQL 命令“DROP TABLE {table name}”。删除表时,MySQL 将删除外键。

public function dropTable($table)
{
    echo "    > drop table $table ...";
    $time=microtime(true);
    $this->getDbConnection()->createCommand()->dropTable($table);
    echo " done (time: ".sprintf('%.3f', microtime(true)-$time)."s)\n";
}
于 2013-07-11T20:33:21.087 回答