phinx
phinx copied to clipboard
Cannot change primary key to multi-column one with SQLite
When using the SQLite adapter, tables can be created with a multi-column primary key.
Trying to change the primary key to a multi-column one afterwards fails (whether it previously was a single-column or multi-column one) with InvalidArgumentException "Invalid value for primary key: [...]".
Could you provide an example migration?
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class Foo extends AbstractMigration
{
public function change(): void
{
$this->create();
$this->modify();
}
private function create(): void
{
$this->table('foo', ['id' => false, 'primary_key' => ['foo_id1', 'foo_id2']])
->addColumn('foo_id1', 'integer')
->addColumn('foo_id2', 'integer')
->create();
}
private function modify(): void
{
$this->table('foo')->addColumn('foo_bar', 'string')->save();
$this->table('foo')->changePrimaryKey(['foo_bar', 'foo_id1', 'foo_id2'])->save();
}
}
I'm experiencing the same problem although in my case I'm trying to remove composite key and replace it with single column.
public function change()
{
$this->table('orders')
->changePrimaryKey('id')
->changeColumn('id', 'integer', ['identity' => true])
->update();
}