修复安装数据库报错

This commit is contained in:
2026-03-21 15:48:48 +08:00
parent f0d1d46457
commit f4233e751e
3 changed files with 75 additions and 0 deletions

View File

@@ -227,6 +227,8 @@ class Install extends AbstractMigration
->addColumn('extend', 'string', ['limit' => 255, 'default' => '', 'comment' => '扩展属性', 'null' => false])
->addColumn('allow_del', 'integer', ['signed' => false, 'limit' => MysqlAdapter::INT_TINY, 'default' => 0, 'comment' => '允许删除:0=否,1=是', 'null' => false])
->addColumn('weigh', 'integer', ['comment' => '权重', 'default' => 0, 'null' => false])
->addColumn('update_time', 'biginteger', ['limit' => 16, 'signed' => false, 'null' => true, 'default' => null, 'comment' => '更新时间'])
->addColumn('create_time', 'biginteger', ['limit' => 16, 'signed' => false, 'null' => true, 'default' => null, 'comment' => '创建时间'])
->addIndex(['name'], [
'unique' => true,
])

View File

@@ -0,0 +1,55 @@
<?php
/**
* config 表在初始 install 中未含 create_time/update_time而 Config 模型开启自动时间戳,
* Version205 等迁移使用 Model::save() 会生成对 update_time 的 UPDATE导致 1054 错误。
* 本迁移在 Version205 之前执行,补齐字段。
*/
use Phinx\Migration\AbstractMigration;
class AddConfigTimestamps extends AbstractMigration
{
public function up(): void
{
if (!$this->hasTable('config')) {
return;
}
$config = $this->table('config');
if (!$config->hasColumn('update_time')) {
$config->addColumn('update_time', 'biginteger', [
'limit' => 16,
'signed' => false,
'null' => true,
'default' => null,
'comment' => '更新时间',
'after' => 'weigh',
])->save();
}
$config = $this->table('config');
if (!$config->hasColumn('create_time')) {
$config->addColumn('create_time', 'biginteger', [
'limit' => 16,
'signed' => false,
'null' => true,
'default' => null,
'comment' => '创建时间',
'after' => 'update_time',
])->save();
}
}
public function down(): void
{
if (!$this->hasTable('config')) {
return;
}
$config = $this->table('config');
if ($config->hasColumn('create_time')) {
$config->removeColumn('create_time')->save();
}
$config = $this->table('config');
if ($config->hasColumn('update_time')) {
$config->removeColumn('update_time')->save();
}
}
}