如何在 PostgreSQL 的 phinx 中将 'id' 设置为大整数并自动增量?

问题描述 投票:0回答:2

我尝试仅设置为biginter,但它失去了自动增量属性。所以我也尝试添加自动增量。

$table->changeColumn('id', 'biginteger', ['identity' => true])->update();

但是显示错误。

PDOException: SQLSTATE[42704]: Undefined object: 7 ERROR:  type "bigserial" does not exist

这对于 PostgreSQL 来说怎么可能?

php database database-migration phinx
2个回答
0
投票

对于 MySQL,这适用于 phinx 0.12

$table = $this->table('mytable', ['id' => false, 'primary_key' => 'id']);
$table->addColumn('id', 'biginteger', ['identity' => true, 'signed' => false])->create();

0
投票

尝试10种或更多方法后...

        $this->table('usuario', ['id' => true, 'primary_key' => 'id'])
        //$table->addColumn('id', 'biginteger', ['identity' => true])
        //$table->addColumn('id', 'biginteger')
        ->addColumn('nome', 'string', ['limit' => 100])
....

并确保在配置文件中添加

 'testing' => [
        'adapter' => 'pgsql',
        'host' => 'xxxx',
        'name' => 'zzzz',
        'user' => 'postgres',
        'pass' => 'postgres',
        'port' => '5432',
        'charset' => 'utf8',
        'schema' => 'public' <-- add this
    ]
© www.soinside.com 2019 - 2024. All rights reserved.