php-Phalcon迁移系统中的auto_increment
作者:互联网
由于某些原因,迁移系统在使用auto_increment主键时表现不佳.我在监督什么吗? (我正在使用Phalcon 2.0.1)
我有以下自动生成的迁移:
class LanguagesMigration_100 extends Migration
{
public function up()
{
$this->morphTable(
'languages',
array(
'columns' => array(
new Column(
'id',
array(
'type' => Column::TYPE_INTEGER,
'notNull' => true,
'autoIncrement' => true,
'size' => 11,
'first' => true
)
),
new Column(
'ccode',
array(
'type' => Column::TYPE_VARCHAR,
'notNull' => true,
'size' => 6,
'after' => 'id'
)
),
new Column(
'active',
array(
'type' => Column::TYPE_INTEGER,
'notNull' => true,
'size' => 1,
'after' => 'ccode'
)
)
),
'indexes' => array(
new Index('PRIMARY', array('id')),
new Index('UNIQ_A0D153794EE11504', array('ccode'))
),
'options' => array(
'TABLE_TYPE' => 'BASE TABLE',
'AUTO_INCREMENT' => '9',
'ENGINE' => 'InnoDB',
'TABLE_COLLATION' => 'utf8_unicode_ci'
)
)
);
}
}
但是,当我运行该迁移时,生成的sql会:
==> default: Phalcon DevTools (2.0.1)
==> default: 1432127144.0475
==> default: :
==> default: SELECT IF(COUNT(*)>0, 1 , 0) FROM `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_NAME`= 'languages' AND `TABLE_SCHEMA` = 'euromillions'
==> default: =>
==> default: 1432127144.0619
==> default: (
==> default: 0.014361143112183
==> default: )
==> default: 1432127144.0767
==> default: :
==> default: DESCRIBE `euromillions`.`languages`
==> default: =>
==> default: 1432127144.1014
==> default: (
==> default: 0.024682998657227
==> default: )
==> default: 1432127144.1033
==> default: :
==> default: ALTER TABLE `languages` MODIFY `id` INT(11) NOT NULL
==> default: => 1432127144.1488 (0.045513153076172)
==> default: 1432127144.1489: ALTER TABLE `languages` ADD `active` INT(1) NOT NULL AFTER ccode
==> default: => 1432127144.17 (0.021080017089844)
==> default: 1432127144.1701: SHOW INDEXES FROM `euromillions`.`languages`
==> default: => 1432127144.1715 (0.001410961151123)
==> default: 1432127144.1717: ALTER TABLE `languages` ADD INDEX `UNIQ_A0D153794EE11504` (`ccode`)
==> default: => 1432127144.181 (0.0093460083007812)
==> default: 1432127144.1811: ALTER TABLE `languages` DROP INDEX `ccode`
==> default: => 1432127144.185 (0.0038588047027588)
==> default: 1432127144.185: ALTER TABLE `languages` DROP INDEX `ccode_2`
==> default: => 1432127144.1883 (0.0032830238342285)
==> default:
==> default: Success: Version 1.0.0 was successfully migrated
如您所见,修改了id字段,其中不包含auto_increment.
解决方法:
我正在回答自己的问题,因为这似乎是Phalcon迁移系统中的错误.
正如@axalix指出的那样,迁移是在以前存在的表上完成的. (我支持您的回答,因为它帮助我找到了解决方案).
这是原始表:
CREATE TABLE `languages` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`ccode` varchar(6) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `ccode` (`ccode`),
KEY `ccode_2` (`ccode`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
这是修改后的表(由主义orm:schema-tool修改)
CREATE TABLE `languages` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`ccode` varchar(6) COLLATE utf8_unicode_ci NOT NULL,
`active` tinyint(1) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UNIQ_A0D153794EE11504` (`ccode`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
原来,我忘记了Doctrine实体中的“ unsigned”选项,因此,在更改表时,该表看起来像
CREATE TABLE `languages` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ccode` varchar(6) COLLATE utf8_unicode_ci NOT NULL,
`active` tinyint(1) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UNIQ_A0D153794EE11504` (`ccode`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
出于某种原因,在不使用unsigned选项的情况下运行phalcon迁移会使其忘记auto_increment.
我将尝试单独复制它,以将错误报告给Phalcon家伙.
标签:phalcon,database-migration,auto-increment,mysql,php 来源: https://codeday.me/bug/20191120/2042851.html