phinx icon indicating copy to clipboard operation
phinx copied to clipboard

SQLiteAdapter adds autoincrement to integer column when changing primary key

Open MasterOdin opened this issue 7 months ago • 1 comments

If I do:

        $this->table('foo')
            ->addColumn('id_2', 'integer')
            ->create();

        $this->table('foo')
            ->changePrimaryKey('id_2')
            ->update();

After the create I'll have:

CREATE TABLE `foo` (`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, `id_2` INTEGER NULL);

and after the update I'll have:

CREATE TABLE IF NOT EXISTS "foo" (`id` INTEGER NOT NULL, `id_2` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT);

where even though didn't specify it, id_2 now has AUTOINCREMENT because it's an integer column. None of the other adapters does this, and it doesn't make sense that sqlite does either.

MasterOdin avatar Jun 12 '25 21:06 MasterOdin

Solved in https://github.com/cakephp/migrations/pull/954 for Migrations. Feel free to port, seems like an important fix.

dereuromark avatar Nov 10 '25 19:11 dereuromark