Migration Yii迁移dropTable和FK

Migration Yii迁移dropTable和FK,migration,yii,Migration,Yii,我有以下几点: 功能启动: $this->createTable( 'vacancy_moderate', array( 'id' => 'int(10) unsigned NOT NULL AUTO_INCREMENT', 'period_days' => 'tinyint(4) NOT NULL', 'title' => 'v

我有以下几点:

功能启动:

$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中?

它们将随表一起删除,因为一切都将消失。:-)

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";
}