Devyash Sanghai
Devyash Sanghai

Reputation: 33

Delete raises integrity error

I have 2 tables:

Question: 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

Answers (1)

Zbynek Vyskovsky - kvr000
Zbynek Vyskovsky - kvr000

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

Related Questions