Home > other >  Uncaught Error: UNIQUE constraint failed: award.award_id
Uncaught Error: UNIQUE constraint failed: award.award_id

Time:10-29

I am trying to create table named award and insert the values I had wrote, but I am getting no luck in trying to figure out the issue.

CREATE TABLE award
(
    award_id varchar(50) NOT NULL,
    year int NOT NULL,
    category varchar(50) NOT NULL,
    movie_id CHAR(3) NOT NULL,
    star_id CHAR(3) NOT NULL,
    PRIMARY KEY (award)
    FOREIGN KEY (movie_id) REFERENCES movie (movie_id),
    FOREIGN KEY (star_id) REFERENCES star (star_id)
);

INSERT INTO award (award_id, year, category, movie_id, star_id) 
VALUES ('oscars', 2016, 'best_picture', 108, 210),
       ('oscars', 2019, 'best_director', 109, 211),
       ('oscars', 2010, 'best_actress', 110, 212),
       ('oscars', 2021, 'best_actor', 111, 213),
       ('cannes', 2011, 'best_actress', 112, 214),
       ('cannes', 2000, 'best_actor', 113, 215);

I am trying to create an award table with the insertions I added.

CodePudding user response:

Your has primary key [award], but you try insert values without it. Create table with AUTO INCREMENT.

CodePudding user response:

award_id (primary_key) must be unique.

  • Related