Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlite rollback fails when primary key is changed and old pk column is dropped #201

Open
jayvdb opened this issue Mar 7, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@jayvdb
Copy link
Collaborator

jayvdb commented Mar 7, 2024

We had a table with two id column, and switched the pk from one id to the other id column, and dropped the old id column.

i.e. before

CREATE TABLE Foo (
id_not_needed TEXT NOT NULL PRIMARY KEY,
id TEXT NOT NULL ,
blah TEXT 
);

after

CREATE TABLE Foo (
id TEXT NOT NULL  PRIMARY KEY ,
blah TEXT 
);

The migration works well.
However rollback fails because it starts with

ALTER TABLE Foo ADD COLUMN id_not_needed TEXT NOT NULL PRIMARY KEY DEFAULT null;
...

This fails with

Encountered unexpected error: Sqlite error Cannot add a PRIMARY KEY column

I havent checked postgres - quite possible it has a similar problem.

Then, even if the DDL is fixed, there is still the fact that recreating the old pk column cant become the primary key unless the the recreated column is given values for the existing rows, and how to populate that field cant easily be automatically generated.

@jayvdb jayvdb changed the title sqlite rollback fails on change of primary key sqlite rollback fails when primary key is changed and old pk column is dropped Mar 7, 2024
@Electron100 Electron100 added the bug Something isn't working label Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants