Skip to content

Instantly share code, notes, and snippets.

@wilcorrea
Created January 30, 2020 02:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wilcorrea/472bd0a492502491b32622eb32c1feca to your computer and use it in GitHub Desktop.
Save wilcorrea/472bd0a492502491b32622eb32c1feca to your computer and use it in GitHub Desktop.
<?php
class BlaBlaBla extends Migration
{
// ... up, down whatever
protected function existsForeignKey($table, $foreignKey)
{
$sql = "SELECT KEY_COLUMN_USAGE.CONSTRAINT_NAME
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE KEY_COLUMN_USAGE.TABLE_NAME = '{$table}' AND KEY_COLUMN_USAGE.COLUMN_NAME = '{$foreignKey}'";
$command = $this->db->createCommand($sql);
return count($command->queryAll()) > 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment