Skip to content

Adding IntColumn as primary key to existing table #2062

Answered by simolus3
moritz-weber asked this question in Q&A
Discussion options

You must be logged in to vote

Your approach for the migration gets pretty close. For me, it works after I remove the addColumn statement altogether - the single alterTable call is enough.

Technically speaking, the problem is not that rowId can be null (it can't). Your migration fails at the addColumn call since the added column is non-nullable. Non-nullable columns can't be added via ALTER TABLE ADD COLUMN (which addColumn uses internally) because existing rows in the table would illegally have a null value then.
On the other hand, alterTable runs a rather complex procedure that involves creating a new table from scratch, copying data over, and then replacing the old table with the new one. This means that it can crea…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@moritz-weber
Comment options

Answer selected by moritz-weber
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants