We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Migration problem with Foreign key

Hello everybody! I'm trying to create a tool that auto generates the migration files of my phalcon application. I have a very strange bahaviour while i am trying to add a foreign key to a table.

I am using 2.0.8 version.

First of all this is the code in the migration class.

<?php

use Phalcon\Db\Reference;
use Phalcon\Mvc\Model\Migration;

class CustomMigration_100 extends Migration {

    public function up() {
        self::$_connection->addForeignKey('child', self::getDbName(), new Reference('child_1', array(
            'referencedTable' => 'dad',
            'columns' => array('dad1'),
            'referencedColumns' => array('my1'),
            'onUpdate' => 'RESTRICT',
            'onDelete' => 'RESTRICT')
        ));

        self::$_connection->addForeignKey('child', self::getDbName(), new Reference('child_2', array(
            'referencedTable' => 'dad',
            'columns' => array('dad2'),
            'referencedColumns' => array('my2'),
            'onUpdate' => 'RESTRICT',
            'onDelete' => 'RESTRICT')
        ));
    }

}

Now, when i run the migration from the command prompt it succeeds but creates the foreign key with "NO ACTION" But if I run the same commands from into the MySQL Workbench (I copy - paste the commands from the result of the command prompt migration) it works fine!

Any ideas? Thanx in advance!

it might be a bug or some parts are not properly implemented in Phalcon. You can submit a bug report on github

https://github.com/phalcon/cphalcon/issues



2.9k

Thanx for the reply. I just did. (#11083)