Reputation: 33
I have 2 tables:
Users
with U_Id
as primary keyVotes
with V_author
which refers to Users(U_Id)
as foreign keyQuestion: How to delete rows from Users
table?
When I try to do that I get the error below.
Error: psycopg2.IntegrityError: update or delete on table "users" violates foreign key constraint "votes_v_author_fkey" on tabl e "votes" DETAIL: Key (u_id)=(7) is still referenced from table "votes".
Upvotes: 0
Views: 550
Reputation: 18825
As described in the error, there is a record in Votes
table, which refers to about to be deleted record from Users
table. You need to delete the records from child table first:
DELETE FROM Votes WHERE v_author = 7
Upvotes: 1