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

Delete a foreign key #1246

Closed
yotamkr opened this issue Nov 14, 2023 · 5 comments
Closed

Delete a foreign key #1246

yotamkr opened this issue Nov 14, 2023 · 5 comments
Labels

Comments

@yotamkr
Copy link

yotamkr commented Nov 14, 2023

Is there a way to delete a foreign key?
I have two tables, A and B. Rows in A refer to rows in B.
I would like to delete a row in B, and to reset the foreign key in A.
How do I do that?

Example:
class A:
int _id;
string name;
std:shared_ptr key;

class B:
int _id;
I tried to reset the key ptr and update the row, but reveiced "FOREIGN KEY constraint failed: constraint failed";
Also tried to do key = nullptr, but the same error.

Yotam

@fnc12
Copy link
Owner

fnc12 commented Nov 14, 2023

first you need to remove A column values in all rows which have values equal to fk you want to remove. Next remove B row

@fnc12 fnc12 added the question label Nov 14, 2023
@yotamkr
Copy link
Author

yotamkr commented Nov 14, 2023

And how do I remove values from a specific column in the row?
I tried to use storage.update with a nullptr value for the key variable, but that didn't work.

@fnc12
Copy link
Owner

fnc12 commented Nov 14, 2023

And how do I remove values from a specific column in the row?

How do you do same things with raw SQLite? You can either remove the whole row with DELETE FROM ... or by UPDATE.

Anyway how would you do the same in raw SQLite? When you understand what to do with raw SQLite (e.g. with any SQLite client) you will understand what to do with sqlite_orm

@fnc12
Copy link
Owner

fnc12 commented May 16, 2024

@yotamkr is this issue actual?

@yotamkr yotamkr closed this as completed May 16, 2024
@yotamkr
Copy link
Author

yotamkr commented May 16, 2024

Not anymore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants