public function buildColumnSql(SchemaInterface $schema, DeclareColumn $column)
{
$name = $column->name;
$isa = $column->isa ?: 'str';
if (!$column->type && $isa == 'str') {
$column->type = 'text';
}
$args = new ArgumentArray();
$sql = $column->buildDefinitionSql($this->driver, $args);
/*
BUILD COLUMN REFERENCE
track(
FOREIGN KEY(trackartist) REFERENCES artist(artistid)
artist_id INTEGER REFERENCES artist
)
And here is the important part:
Furthermore, MySQL parses but ignores “inline REFERENCES
specifications” (as defined in the SQL standard) where the references
are defined as part of the column specification.
MySQL accepts REFERENCES clauses only when specified as part of a
separate FOREIGN KEY specification. For storage engines that do not
support foreign keys (such as MyISAM), MySQL Server parses and ignores
foreign key specifications.
A column with foreign key should not be nullable.
@see http://stackoverflow.com/questions/10028214/add-foreign-key-to-existing-table
*/
foreach ($schema->relations as $rel) {
switch ($rel['type']) {
case Relationship::BELONGS_TO:
if ($name != 'id' && $rel['self_column'] == $name) {
$fSchema = new $rel['foreign_schema']();
$fColumn = $rel['foreign_column'];
}
break;
}
}
return $sql;
}