Why am I getting ERROR: duplicate key value violates unique constraint "movies_pkey'PostgreSQL duplicate key...

Confusion with the nameplate of an induction motor

Rejected in 4th interview round citing insufficient years of experience

Can the druid cantrip Thorn Whip really defeat a water weird this easily?

It's a yearly task, alright

Can infringement of a trademark be pursued for using a company's name in a sentence?

Is it true that real estate prices mainly go up?

Is "history" a male-biased word ("his+story")?

Humans have energy, but not water. What happens?

Ban on all campaign finance?

what does the apostrophe mean in this notation?

Is a lawful good "antagonist" effective?

Coworker uses her breast-pump everywhere in the office

How do anti-virus programs start at Windows boot?

Best mythical creature to use as livestock?

How to deal with a cynical class?

This equation is outside the page, how to modify it

What happens with multiple copies of Humility and Glorious Anthem on the battlefield?

Is it illegal in Germany to take sick leave if you caused your own illness with food?

What is the blue range indicating on this manifold pressure gauge?

Question about partial fractions with irreducible quadratic factors

Replacing Windows 7 security updates with anti-virus?

"One can do his homework in the library"

Can you reject a postdoc offer after the PI has paid a large sum for flights/accommodation for your visit?

Is having access to past exams cheating and, if yes, could it be proven just by a good grade?



Why am I getting ERROR: duplicate key value violates unique constraint "movies_pkey'


PostgreSQL duplicate key violates unique constraint errorPossible to have nested inserts in Postgres 8.4?Duplicate key violates unique constraintduplicate key violates unique constraint when using multi-threadingERROR: duplicate key value violates unique constraint “repl_stat”Duplicate key value violates a unique constraintKey/value table: what is a good way to organize it if value could be foreign key?postgres PITR from WAL without changesHow to fix all duplicate key value violates unique constraintPostgresql Restore - duplicate key value violates unique constraint













0















So, I'm creating a database for one of my classes using pg admin. I got all the data in no problem but my one issue is this one error that I don't really understand.



ERROR: duplicate key value violates unique contraint "movies_pkey"
DETAIL: key(movie_num)=20 already exists


The above is the error I am getting.



-- DROP'ping tables clear out any existing data
DROP TABLE IF EXISTS movies;
DROP TABLE IF EXISTS actors;

-- CREATE the table, note that id has to be unique, and you must have a name
CREATE TABLE actors(
id INTEGER PRIMARY KEY,
name VARCHAR(20) NOT NULL
);

INSERT INTO actors(id, name) VALUES(
1,
'Sean Connery');
INSERT INTO actors(id, name) VALUES(
2,
'George Lazenby');
INSERT INTO actors(id, name) VALUES(
3,
'Roger Moore');
INSERT INTO actors(id, name) VALUES(
4,
'Timothy Dalton');
INSERT INTO actors(id, name) VALUES(
5,
'Pierce Brosnan');

INSERT INTO actors(id, name) VALUES(
6,
'Daniel Craig');


-- CREATE the table, note movie_num is unique and title and year are required fields, though the actor can be optionally empty
CREATE TABLE movies(
movie_num INTEGER PRIMARY KEY,
title VARCHAR(35) NOT NULL,
actor INTEGER,
year INTEGER NOT NULL
);

INSERT INTO movies(movie_num, title, actor, year)
VALUES(
2,
'From Russia With Love',
1,
1963);
INSERT INTO movies(movie_num, title, actor, year)
VALUES(
3,
'Goldfinger',
1,
1964);
INSERT INTO movies(movie_num, title, actor, year) VALUES(
4,
'Thunderball',
1,
1965);
INSERT INTO movies(movie_num, title, actor, year) VALUES(
5,
'You Only Live Twice',
1,
1967);
INSERT INTO movies(movie_num, title, actor, year) VALUES(
6,
'On Her Majesty''s Secret Service',
2,
1969);
INSERT INTO movies(movie_num, title, actor, year) VALUES(
7,
'Diamonds Are Forever',
1,
1971);
INSERT INTO movies(movie_num, title, actor, year) VALUES(
8,
'Live and Let Die',
3,
1973);
INSERT INTO movies(movie_num, title, actor, year) VALUES(
9,
'The Man With The Golden Gun',
3,
1974);
INSERT INTO movies(movie_num, title, actor, year) VALUES(
10,
'The Spy Who Loved Me',
3,
1977);
INSERT INTO movies(movie_num, title, actor, year) VALUES(
11,
'Moonraker',
3,
1979);
INSERT INTO movies(movie_num, title, actor, year) VALUES(
12,
'For Your Eyes Only',
3,
1981);
INSERT INTO movies(movie_num, title, actor, year) VALUES(
14,
'A View To A Kill',
3,
1985);
INSERT INTO movies(movie_num, title, actor, year) VALUES(
15,
'The Living Daylights',
4,
1987);
INSERT INTO movies(movie_num, title, actor, year) VALUES(
16,
'License To Kill',
4,
1989);
INSERT INTO movies(movie_num, title, actor, year) VALUES(
18,
'Tomorrow Never Dies',
5,
1997);
INSERT INTO movies(movie_num, title, actor, year) VALUES(
20,
'Die Another Day',
5,
2003);
INSERT INTO movies(movie_num, title, actor, year) VALUES(
1,
'Dr. No',
1,
1962);
INSERT INTO movies(movie_num, title, actor, year) VALUES(
13,
'Octopussy',
3,
1983);
INSERT INTO movies(movie_num, title, actor, year) VALUES(
17,
'Goldeneye',
5,
1995);
INSERT INTO movies(movie_num, title, actor, year) VALUES(
19,
'The World Is Not Enough',
5,
1999);
INSERT INTO movies(movie_num, title, actor, year) VALUES(
20,
'Casino Royale',
6,
2006);
INSERT INTO movies(movie_num, title, actor, year) VALUES(
21,
'Quantum of Solace',
6,
2008);
INSERT INTO movies(movie_num, title, actor, year) VALUES(
22,
'Skyfall',
6,
2012);
INSERT INTO movies(movie_num, title, actor, year) VALUES(
23,
'Spectre',
6,
2015);


And this is the database I created.



Any help is much appreciated.









share







New contributor




Dee Slotegraaf is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    0















    So, I'm creating a database for one of my classes using pg admin. I got all the data in no problem but my one issue is this one error that I don't really understand.



    ERROR: duplicate key value violates unique contraint "movies_pkey"
    DETAIL: key(movie_num)=20 already exists


    The above is the error I am getting.



    -- DROP'ping tables clear out any existing data
    DROP TABLE IF EXISTS movies;
    DROP TABLE IF EXISTS actors;

    -- CREATE the table, note that id has to be unique, and you must have a name
    CREATE TABLE actors(
    id INTEGER PRIMARY KEY,
    name VARCHAR(20) NOT NULL
    );

    INSERT INTO actors(id, name) VALUES(
    1,
    'Sean Connery');
    INSERT INTO actors(id, name) VALUES(
    2,
    'George Lazenby');
    INSERT INTO actors(id, name) VALUES(
    3,
    'Roger Moore');
    INSERT INTO actors(id, name) VALUES(
    4,
    'Timothy Dalton');
    INSERT INTO actors(id, name) VALUES(
    5,
    'Pierce Brosnan');

    INSERT INTO actors(id, name) VALUES(
    6,
    'Daniel Craig');


    -- CREATE the table, note movie_num is unique and title and year are required fields, though the actor can be optionally empty
    CREATE TABLE movies(
    movie_num INTEGER PRIMARY KEY,
    title VARCHAR(35) NOT NULL,
    actor INTEGER,
    year INTEGER NOT NULL
    );

    INSERT INTO movies(movie_num, title, actor, year)
    VALUES(
    2,
    'From Russia With Love',
    1,
    1963);
    INSERT INTO movies(movie_num, title, actor, year)
    VALUES(
    3,
    'Goldfinger',
    1,
    1964);
    INSERT INTO movies(movie_num, title, actor, year) VALUES(
    4,
    'Thunderball',
    1,
    1965);
    INSERT INTO movies(movie_num, title, actor, year) VALUES(
    5,
    'You Only Live Twice',
    1,
    1967);
    INSERT INTO movies(movie_num, title, actor, year) VALUES(
    6,
    'On Her Majesty''s Secret Service',
    2,
    1969);
    INSERT INTO movies(movie_num, title, actor, year) VALUES(
    7,
    'Diamonds Are Forever',
    1,
    1971);
    INSERT INTO movies(movie_num, title, actor, year) VALUES(
    8,
    'Live and Let Die',
    3,
    1973);
    INSERT INTO movies(movie_num, title, actor, year) VALUES(
    9,
    'The Man With The Golden Gun',
    3,
    1974);
    INSERT INTO movies(movie_num, title, actor, year) VALUES(
    10,
    'The Spy Who Loved Me',
    3,
    1977);
    INSERT INTO movies(movie_num, title, actor, year) VALUES(
    11,
    'Moonraker',
    3,
    1979);
    INSERT INTO movies(movie_num, title, actor, year) VALUES(
    12,
    'For Your Eyes Only',
    3,
    1981);
    INSERT INTO movies(movie_num, title, actor, year) VALUES(
    14,
    'A View To A Kill',
    3,
    1985);
    INSERT INTO movies(movie_num, title, actor, year) VALUES(
    15,
    'The Living Daylights',
    4,
    1987);
    INSERT INTO movies(movie_num, title, actor, year) VALUES(
    16,
    'License To Kill',
    4,
    1989);
    INSERT INTO movies(movie_num, title, actor, year) VALUES(
    18,
    'Tomorrow Never Dies',
    5,
    1997);
    INSERT INTO movies(movie_num, title, actor, year) VALUES(
    20,
    'Die Another Day',
    5,
    2003);
    INSERT INTO movies(movie_num, title, actor, year) VALUES(
    1,
    'Dr. No',
    1,
    1962);
    INSERT INTO movies(movie_num, title, actor, year) VALUES(
    13,
    'Octopussy',
    3,
    1983);
    INSERT INTO movies(movie_num, title, actor, year) VALUES(
    17,
    'Goldeneye',
    5,
    1995);
    INSERT INTO movies(movie_num, title, actor, year) VALUES(
    19,
    'The World Is Not Enough',
    5,
    1999);
    INSERT INTO movies(movie_num, title, actor, year) VALUES(
    20,
    'Casino Royale',
    6,
    2006);
    INSERT INTO movies(movie_num, title, actor, year) VALUES(
    21,
    'Quantum of Solace',
    6,
    2008);
    INSERT INTO movies(movie_num, title, actor, year) VALUES(
    22,
    'Skyfall',
    6,
    2012);
    INSERT INTO movies(movie_num, title, actor, year) VALUES(
    23,
    'Spectre',
    6,
    2015);


    And this is the database I created.



    Any help is much appreciated.









    share







    New contributor




    Dee Slotegraaf is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      0












      0








      0








      So, I'm creating a database for one of my classes using pg admin. I got all the data in no problem but my one issue is this one error that I don't really understand.



      ERROR: duplicate key value violates unique contraint "movies_pkey"
      DETAIL: key(movie_num)=20 already exists


      The above is the error I am getting.



      -- DROP'ping tables clear out any existing data
      DROP TABLE IF EXISTS movies;
      DROP TABLE IF EXISTS actors;

      -- CREATE the table, note that id has to be unique, and you must have a name
      CREATE TABLE actors(
      id INTEGER PRIMARY KEY,
      name VARCHAR(20) NOT NULL
      );

      INSERT INTO actors(id, name) VALUES(
      1,
      'Sean Connery');
      INSERT INTO actors(id, name) VALUES(
      2,
      'George Lazenby');
      INSERT INTO actors(id, name) VALUES(
      3,
      'Roger Moore');
      INSERT INTO actors(id, name) VALUES(
      4,
      'Timothy Dalton');
      INSERT INTO actors(id, name) VALUES(
      5,
      'Pierce Brosnan');

      INSERT INTO actors(id, name) VALUES(
      6,
      'Daniel Craig');


      -- CREATE the table, note movie_num is unique and title and year are required fields, though the actor can be optionally empty
      CREATE TABLE movies(
      movie_num INTEGER PRIMARY KEY,
      title VARCHAR(35) NOT NULL,
      actor INTEGER,
      year INTEGER NOT NULL
      );

      INSERT INTO movies(movie_num, title, actor, year)
      VALUES(
      2,
      'From Russia With Love',
      1,
      1963);
      INSERT INTO movies(movie_num, title, actor, year)
      VALUES(
      3,
      'Goldfinger',
      1,
      1964);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      4,
      'Thunderball',
      1,
      1965);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      5,
      'You Only Live Twice',
      1,
      1967);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      6,
      'On Her Majesty''s Secret Service',
      2,
      1969);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      7,
      'Diamonds Are Forever',
      1,
      1971);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      8,
      'Live and Let Die',
      3,
      1973);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      9,
      'The Man With The Golden Gun',
      3,
      1974);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      10,
      'The Spy Who Loved Me',
      3,
      1977);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      11,
      'Moonraker',
      3,
      1979);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      12,
      'For Your Eyes Only',
      3,
      1981);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      14,
      'A View To A Kill',
      3,
      1985);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      15,
      'The Living Daylights',
      4,
      1987);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      16,
      'License To Kill',
      4,
      1989);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      18,
      'Tomorrow Never Dies',
      5,
      1997);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      20,
      'Die Another Day',
      5,
      2003);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      1,
      'Dr. No',
      1,
      1962);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      13,
      'Octopussy',
      3,
      1983);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      17,
      'Goldeneye',
      5,
      1995);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      19,
      'The World Is Not Enough',
      5,
      1999);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      20,
      'Casino Royale',
      6,
      2006);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      21,
      'Quantum of Solace',
      6,
      2008);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      22,
      'Skyfall',
      6,
      2012);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      23,
      'Spectre',
      6,
      2015);


      And this is the database I created.



      Any help is much appreciated.









      share







      New contributor




      Dee Slotegraaf is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      So, I'm creating a database for one of my classes using pg admin. I got all the data in no problem but my one issue is this one error that I don't really understand.



      ERROR: duplicate key value violates unique contraint "movies_pkey"
      DETAIL: key(movie_num)=20 already exists


      The above is the error I am getting.



      -- DROP'ping tables clear out any existing data
      DROP TABLE IF EXISTS movies;
      DROP TABLE IF EXISTS actors;

      -- CREATE the table, note that id has to be unique, and you must have a name
      CREATE TABLE actors(
      id INTEGER PRIMARY KEY,
      name VARCHAR(20) NOT NULL
      );

      INSERT INTO actors(id, name) VALUES(
      1,
      'Sean Connery');
      INSERT INTO actors(id, name) VALUES(
      2,
      'George Lazenby');
      INSERT INTO actors(id, name) VALUES(
      3,
      'Roger Moore');
      INSERT INTO actors(id, name) VALUES(
      4,
      'Timothy Dalton');
      INSERT INTO actors(id, name) VALUES(
      5,
      'Pierce Brosnan');

      INSERT INTO actors(id, name) VALUES(
      6,
      'Daniel Craig');


      -- CREATE the table, note movie_num is unique and title and year are required fields, though the actor can be optionally empty
      CREATE TABLE movies(
      movie_num INTEGER PRIMARY KEY,
      title VARCHAR(35) NOT NULL,
      actor INTEGER,
      year INTEGER NOT NULL
      );

      INSERT INTO movies(movie_num, title, actor, year)
      VALUES(
      2,
      'From Russia With Love',
      1,
      1963);
      INSERT INTO movies(movie_num, title, actor, year)
      VALUES(
      3,
      'Goldfinger',
      1,
      1964);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      4,
      'Thunderball',
      1,
      1965);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      5,
      'You Only Live Twice',
      1,
      1967);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      6,
      'On Her Majesty''s Secret Service',
      2,
      1969);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      7,
      'Diamonds Are Forever',
      1,
      1971);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      8,
      'Live and Let Die',
      3,
      1973);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      9,
      'The Man With The Golden Gun',
      3,
      1974);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      10,
      'The Spy Who Loved Me',
      3,
      1977);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      11,
      'Moonraker',
      3,
      1979);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      12,
      'For Your Eyes Only',
      3,
      1981);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      14,
      'A View To A Kill',
      3,
      1985);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      15,
      'The Living Daylights',
      4,
      1987);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      16,
      'License To Kill',
      4,
      1989);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      18,
      'Tomorrow Never Dies',
      5,
      1997);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      20,
      'Die Another Day',
      5,
      2003);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      1,
      'Dr. No',
      1,
      1962);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      13,
      'Octopussy',
      3,
      1983);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      17,
      'Goldeneye',
      5,
      1995);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      19,
      'The World Is Not Enough',
      5,
      1999);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      20,
      'Casino Royale',
      6,
      2006);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      21,
      'Quantum of Solace',
      6,
      2008);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      22,
      'Skyfall',
      6,
      2012);
      INSERT INTO movies(movie_num, title, actor, year) VALUES(
      23,
      'Spectre',
      6,
      2015);


      And this is the database I created.



      Any help is much appreciated.







      postgresql pgadmin





      share







      New contributor




      Dee Slotegraaf is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share







      New contributor




      Dee Slotegraaf is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share



      share






      New contributor




      Dee Slotegraaf is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 2 mins ago









      Dee SlotegraafDee Slotegraaf

      32




      32




      New contributor




      Dee Slotegraaf is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Dee Slotegraaf is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Dee Slotegraaf is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "182"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          Dee Slotegraaf is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f232085%2fwhy-am-i-getting-error-duplicate-key-value-violates-unique-constraint-movies-p%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          Dee Slotegraaf is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          Dee Slotegraaf is a new contributor. Be nice, and check out our Code of Conduct.













          Dee Slotegraaf is a new contributor. Be nice, and check out our Code of Conduct.












          Dee Slotegraaf is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to Database Administrators Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f232085%2fwhy-am-i-getting-error-duplicate-key-value-violates-unique-constraint-movies-p%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Anexo:Material bélico de la Fuerza Aérea de Chile Índice Aeronaves Defensa...

          Always On Availability groups resolving state after failover - Remote harden of transaction...

          update json value to null Announcing the arrival of Valued Associate #679: Cesar Manara ...