I'm trying to run a migration with Phalcon (Devtools 2.0.10) but it keeps complaining about ERROR: SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
I've run migrations with this last week and they all worked fine, not sure what is different now. I've scrapped the database, reinstalled mysql, recreated the database, still does the same thing.
The problem seems to be related to foreign keys in general and not specifically these ones. It starts by complaining about a specific model, so I removed the references
statement just to see, and it stops at the next foreign key declaration and so on. The engine is set to InnoDB, the types of the keys match and it runs fine on my colleague's machine so I'm sure it's not a syntax problem but rather something specific about SQL (server)
class ModuleTranslationsMigration_100 extends Migration
{
public function morph()
{
$this->morphTable('', array(
...
'references' => array(
new Reference(
'module_translations_ibfk_1',
array(
'referencedSchema' => 'learning',
'referencedTable' => 'modules',
'columns' => array('module_id'),
'referencedColumns' => array('id')
)
),
new Reference(
'module_translations_ibfk_2',
array(
'referencedSchema' => 'learning',
'referencedTable' => 'languages',
'columns' => array('language_id'),
'referencedColumns' => array('id')
)
)
),
...
class LanguagesMigration_100 extends Migration
{
public function morph()
{
$this->morphTable('languages', array(
'columns' => array(
new Column(
'id',
array(
'type' => Column::TYPE_CHAR,
'notNull' => true,
'size' => 2,
'first' => true
)
),
...
class ModulesMigration_100 extends Migration
{
public function morph()
{
$this->morphTable('modules', array(
'columns' => array(
new Column(
'id',
array(
'type' => Column::TYPE_INTEGER,
'unsigned' => true,
'notNull' => true,
'autoIncrement' => true,
'size' => 10,
'first' => true
)
),
...