Skip to content

Change the PK value while keeping the FK links #2893

Closed Answered by simolus3
CharlotteJu asked this question in Q&A
Discussion options

You must be logged in to vote

Hi! Sure, you can construct that update statement in drift with

  Future<void> updateId(int oldId, int newId) async {
    final stmt = update(table)..where((row) => row.id.equals(oldId));
    await stmt.write(TableCompanion(id: Value(newId)));
  }

Is this what you were looking for? As you've said, this should also update foreign keys if they have an ON UPDATE CASCADE option.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by CharlotteJu
Comment options

You must be logged in to vote
0 replies
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