When creating a migration, I want to make sure that such a foreign key does not exist.
$this->createForeignKey( self::TABLE_NAME, self::COLUMN, self::FOREIGN_TABLE_NAME, 'id', 'SET NULL', 'CASCADE' ); When creating a migration, I want to make sure that such a foreign key does not exist.
$this->createForeignKey( self::TABLE_NAME, self::COLUMN, self::FOREIGN_TABLE_NAME, 'id', 'SET NULL', 'CASCADE' ); public function safeUp() { Yii::$app->db->schema->refreshTableSchema(self::TABLE_NAME); $tableSchema = Yii::$app->db->schema->getTableSchema(self::TABLE_NAME, true); if (!in_array( self::COLUMN, array_keys($tableSchema->foreignKeys) )) { $this->createForeignKey( self::TABLE_NAME, self::COLUMN, self::FOREIGN_TABLE_NAME, 'id', 'SET NULL', 'CASCADE' ); } } Source: https://ru.stackoverflow.com/questions/777010/
All Articles
idx-table_name-column, foreign keys asfk-table_name-column, or evenfk-table_name-column-ref_table-ref_columnn- pa3py6aka