title: Delete records from a table having foreign key constraint in postgres
body: <p>I have a table &quot;titles&quot; and a table &quot;scores&quot; in DB. I have witten a query to remove old_movies, shortfilms, games, episodes from my &quot;titles&quot; table. But when i run the query i am getting the below shown error.</p>
  <blockquote>
  <p>ERROR:  update or delete on table &quot;titles&quot; violates foreign key
  constraint &quot;scores_fk&quot; on table &quot;scores&quot;
  DETAIL:  Key (id_titles)=(tt3391132) is still referenced from table &quot;scores&quot;.</p>
  </blockquote>
  <p>I have tried removing the foreign key constraint on the scores table and then tried removing the records, but it didn't work. Later I tried deleting the record first from &quot;scores&quot; table and then from &quot;titles&quot; table, but still it is showing me the error as above. Please help me solve this as I am new to postgres.</p>
  <p>The code to remove records:</p>
  <pre><code>DELETE
  FROM titles
  WHERE content_type = 'game'
  OR extract(year from released) &lt; 1950
  OR runtime &lt; 10
  OR content_type = 'episode'
  </code></pre>
  <p>The code to alter the scores table:</p>
  <pre><code>ALTER TABLE scores
  DROP CONSTRAINT scores_fk
  ,ADD  CONSTRAINT scores_fk
  FOREIGN KEY (id_titles) REFERENCES titles (id_titles) ON DELETE CASCADE;
  </code></pre>