Unable to add an AUTO_INCREMENTING primary key to a populated table that doesn't have one
Open
Nobody has claimed this yet.
support
- Dominant language
- PHP
- Stars
- 4.5k
- Forks
- 884
- PR merge metrics
- No merged PRs in 30d
Description
$tag_data = $this->table('tag_data');
$tag_data
->addColumn(
'td_id',
'integer',
[
'null' => false,
'signed' => false,
'after' => 'tag_id'
]
)
->changePrimaryKey('td_id')
->save();
This doesn't work because it is creating the td_id column and initializing all rows to 0.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the addColumn and changePrimaryKey calls in the migration API and how they handle an existing populated table. Reproduce the shown migration, then inspect related database migration tests if available; done means adding an auto-incrementing primary key without initializing existing rows to zero.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100