yii\db\Migration::dropForeignKey PHP Method

dropForeignKey() public method

Builds a SQL statement for dropping a foreign key constraint.
public dropForeignKey ( string $name, string $table )
$name string the name of the foreign key constraint to be dropped. The name will be properly quoted by the method.
$table string the table whose foreign is to be dropped. The name will be properly quoted by the method.
    public function dropForeignKey($name, $table)
    {
        echo "    > drop foreign key {$name} from table {$table} ...";
        $time = microtime(true);
        $this->db->createCommand()->dropForeignKey($name, $table)->execute();
        echo ' done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
    }

Usage Example

 /**
  * Update ip-geo-base data
  *
  * @throws \yii\base\Exception
  */
 public function actionUpdate()
 {
     $migrate = new Migration();
     $migrate->dropForeignKey('fk-geobase_contact-geobase_city_id', 'geobase_contact');
     $ipGeoBase = new IpGeoBase();
     $ipGeoBase->updateDB();
     $migrate->addForeignKey('fk-geobase_contact-geobase_city_id', 'geobase_contact', 'geobase_city_id', 'geobase_city', 'id', 'CASCADE', 'CASCADE');
 }
All Usage Examples Of yii\db\Migration::dropForeignKey