How can I set 'id' as biginteger and autoincrement in phinx for PostgreSQL?

337 Views Asked by At

I tried to set as only biginter but it lost its autoincrement properties. So I tried adding auto-increment as well.

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

But it showed error.

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

How is this possible for PostgreSQL?

2

There are 2 best solutions below

0
On

After try 10 or more ways...

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

And ensure in config file add

 'testing' => [
        'adapter' => 'pgsql',
        'host' => 'xxxx',
        'name' => 'zzzz',
        'user' => 'postgres',
        'pass' => 'postgres',
        'port' => '5432',
        'charset' => 'utf8',
        'schema' => 'public' <-- add this
    ]
0
On

For MySQL this works in phinx 0.12

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