cakephp / cakephp/phinx

SQLiteAdapter adds autoincrement to integer column when changing primary key

Open
#2,364 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
4.5k
Forks
884
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in the SQLiteAdapter path that handles changePrimaryKey and reproduce the reported create and update SQL. Compare how the primary-key column is rebuilt with other adapters; done means changing the primary key does not add AUTOINCREMENT unless it was explicitly requested.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, sqlite
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.