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.
Exemplo n.º 1
0
 /**
  * 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');
 }
 public function dropTable()
 {
     if ($this->dropOriginTable) {
         if (in_array($this->tableNameRaw, $this->_connection->schema->tableNames)) {
             $schema = $this->_connection->schema->getTableSchema($this->tableNameRaw);
             if ($schema) {
                 $keys = $schema->foreignKeys;
                 if (is_array($keys)) {
                     foreach ($keys as $name => $_next) {
                         $t = [];
                         foreach ($_next as $k => $v) {
                             if (!$k) {
                                 $t['related_table'] = $v;
                             } else {
                                 $t['related_field'] = $v;
                                 $t['field'] = $k;
                             }
                         }
                         try {
                             $keyName = $this->getNameForeignKey($this->tableNameRaw, $t['related_table'], $_next[$t['field']], $t['related_field'], 255);
                             if ($this->hideMigrationOutput) {
                                 ob_start();
                             }
                             $this->migrationClass->dropForeignKey($keyName, $this->tableNameRaw);
                             if ($this->hideMigrationOutput) {
                                 ob_clean();
                                 ob_flush();
                             }
                         } catch (\yii\db\Exception $exp) {
                         }
                     }
                 }
                 if ($this->hideMigrationOutput) {
                     ob_start();
                 }
                 try {
                     $this->migrationClass->dropTable($this->tableNameRaw);
                 } catch (\yii\db\Exception $exp) {
                 } catch (IntegrityException $exp) {
                 }
                 if ($this->hideMigrationOutput) {
                     ob_clean();
                     ob_flush();
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
 /**
  * @inheritdoc
  * Note: table will be auto pefixied if [[$autoWrapTableNames]] is true.
  */
 public function dropForeignKey($name, $table)
 {
     $table = $this->autoWrappedTableName($table);
     return parent::dropForeignKey($name, $table);
 }
Exemplo n.º 4
0
 public function remove()
 {
     return $this->migrate->dropForeignKey($this->getName(), $this->getSourceTable());
 }
Exemplo n.º 5
0
 /**
  * @inheritdoc
  */
 public function dropForeignKey($name, $table)
 {
     $indexName = $name;
     if (preg_match('/\\}\\}$/', $indexName)) {
         $indexName = preg_replace('/^(.*)\\}\\}$/', '$1_idx}}', $indexName);
     } else {
         $indexName .= '_idx';
     }
     parent::dropForeignKey($name, $table);
     $this->dropIndex($indexName, $table);
 }
Exemplo n.º 6
0
 /**
  * Builds a SQL statement for dropping a foreign key constraint.
  * @param string $table the table whose foreign is to be dropped. The name will be properly quoted by the method.
  * @param string|array $columns the name of the column to that the constraint will be added on. If there are multiple columns, separate them with commas or use an array.
  * @param string $name the name of the foreign key constraint to be dropped. The name will be properly quoted by the method.
  */
 public function dropForeignKey($table, $columns, $name = null)
 {
     $name = $name ?: $this->getNameForeignKey($table, $columns);
     parent::dropForeignKey($name, $table);
 }