Mastering Development

Why can’t insert data in the review table?

The error mentions that a violation of foreign key constraints. MY ERROR: sqlalchemy.exc.IntegrityError: (psycopg2.errors.ForeignKeyViolation) insert or update on table “reviews” violates foreign key constraint “reviews_book_id_fkey” DETAIL: Key (book_id)=(770) is not present in table “reviews”. MY QUERY: db.execute(“INSERT INTO reviews (comment, score, user_id, book_id) VALUES (:comment, :score, :user_id, :book_id)”, {“comment”:comment, “score”: score, “user_id”:, “book_id”: book_id}) […]