When importing a text file into a database using Python, error: Duplicate entry ' ... ' for key ' PRIMARY '

Source: Internet
Author: User

The wrong reason is to add the same primary key, I think for a while, I grabbed the data primary key is ISBN ah, it is impossible to heavy ah, so, I went to the database to check the following error ISBN, inserted data also have, because the classification is not the same, so to insert again, this will definitely error, One way to deal with this is to

If you have this record in your database, you can skip this record and change the category of the book in the database to both categories while skipping this record.

Ans = Con.execute ("select * from B where isbn= (%s)", ISBN)
if (ans): Continue
Con.execute ("INSERT Into B (ISBN, BN, BK, BS, author, publisher, Publishdate) values (%s,%s,%s,%s,%s,%s,%s)", ([ISBN, BN, BK, BS, author, publisher, Publishdate]))

So the problem is solved.

When importing a text file into a database using Python, error: Duplicate entry ' ... ' for key ' PRIMARY '

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.