Hi guys,
I have a problem with migrations and FKs with onDelete/onUpdate, for example generate a migration with:
DevTools 2.0.8 - last commit: c2e5aff43aa4fbf919abd13bb7d0ef80efb83f57
Tested with:
Phalcon 2.0.8 - Windows x86 for PHP 5.6.0 (vc11)
XAMPP: 5.6.14 PHP: 5.6.14 MariaDB: 10.1.8
Phalcon 2.0.8 - Windows x86 for PHP 5.5.0 (vc11)
XAMPP: 1.8.3 PHP: 5.5.15 MySQL: 5.5.32
Mysql Table
CREATE TABLE `users` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL,
`email` VARCHAR(255) NOT NULL,
`password` CHAR(60) NOT NULL,
`mustChangePassword` CHAR(1) NULL DEFAULT NULL,
`idProfile` INT(10) UNSIGNED NOT NULL,
`idCompany` INT(10) UNSIGNED NULL DEFAULT NULL,
`banned` CHAR(1) NULL DEFAULT NULL,
`suspended` CHAR(1) NULL DEFAULT NULL,
`active` CHAR(1) NULL DEFAULT NULL,
PRIMARY KEY (`id`),
INDEX `FK_users_profiles` (`idProfile`),
CONSTRAINT `FK_users_profiles` FOREIGN KEY (`idProfile`) REFERENCES `profiles` (`id`) ON UPDATE CASCADE
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
;
Phalcon migration generates FK(references) but missing onUpdate:
<?php
use Phalcon\Db\Column;
use Phalcon\Db\Index;
use Phalcon\Db\Reference;
use Phalcon\Mvc\Model\Migration;
/**
* Class UsersMigration_100
*/
class UsersMigration_100 extends Migration
{
/**
* Define the table structure
*
* @return void
*/
public function morph()
{
$this->morphTable('users', array(
'columns' => array(
new Column(
'id',
array(
'type' => Column::TYPE_INTEGER,
'unsigned' => true,
'notNull' => true,
'autoIncrement' => true,
'size' => 10,
'first' => true
)
),
new Column(
'name',
array(
'type' => Column::TYPE_VARCHAR,
'notNull' => true,
'size' => 255,
'after' => 'id'
)
),
new Column(
'email',
array(
'type' => Column::TYPE_VARCHAR,
'notNull' => true,
'size' => 255,
'after' => 'name'
)
),
new Column(
'password',
array(
'type' => Column::TYPE_CHAR,
'notNull' => true,
'size' => 60,
'after' => 'email'
)
),
new Column(
'mustChangePassword',
array(
'type' => Column::TYPE_CHAR,
'size' => 1,
'after' => 'password'
)
),
new Column(
'idProfile',
array(
'type' => Column::TYPE_INTEGER,
'unsigned' => true,
'notNull' => true,
'size' => 10,
'after' => 'mustChangePassword'
)
),
new Column(
'idCompany',
array(
'type' => Column::TYPE_INTEGER,
'unsigned' => true,
'size' => 10,
'after' => 'idProfile'
)
),
new Column(
'banned',
array(
'type' => Column::TYPE_CHAR,
'size' => 1,
'after' => 'idCompany'
)
),
new Column(
'suspended',
array(
'type' => Column::TYPE_CHAR,
'size' => 1,
'after' => 'banned'
)
),
new Column(
'active',
array(
'type' => Column::TYPE_CHAR,
'size' => 1,
'after' => 'suspended'
)
)
),
'indexes' => array(
new Index('PRIMARY', array('id')),
new Index('FK_users_profiles', array('idProfile'))
),
'references' => array(
new Reference(
'FK_users_profiles',
array(
'referencedSchema' => 'sptn_web',
'referencedTable' => 'profiles',
'columns' => array('idProfile'),
'referencedColumns' => array('id')
)
)
),
'options' => array(
'TABLE_TYPE' => 'BASE TABLE',
'AUTO_INCREMENT' => '1',
'ENGINE' => 'InnoDB',
'TABLE_COLLATION' => 'utf8_general_ci'
),
)
);
}
/**
* Run the migrations
*
* @return void
*/
public function up()
{
}
/**
* Reverse the migrations
*
* @return void
*/
public function down()
{
}
}