MySQL Threw "1062 - Duplicate Entry" Even There Are Not Duplicated Rows

MySQL Threw “1062 – Duplicate Entry” Even There Are Not Duplicated Rows

Outline

    Original Post

    MySQL Threw “1062 – Duplicate Entry” Even There Are Not Duplicated Rows


    When I download broker-level trading data for Taiwan stocks from the internet and use Python to insert it into the MySQL database, MySQL returns the following error message:

    1062 – Duplicate entry ‘2022-02-10-1712-116M-29.65’ for key ‘PRIMARY

    Even after thorough verification using Pandas, it is still unclear where the duplicate data is. Upon closer inspection, there are several possible reasons for this issue, which are enumerated below.

    Null Values

    In theory, Primary Keys are not allowed to be Null, so Null values may lead to insertion errors.

    Collation

    Some databases use case-insensitive encoding, which might be the cause of errors when writing to the database.

    Using Float Column as Primary Key

    According to should we use float as primary key in sql-server, databases usually do not prohibit using a float column as a primary key, but it is strongly discouraged.



    Related Posts

    Aron

    A data scientist working in a retail company, with experience in web design and marketing. Recently dives into cryptocurrency and quantitative investing.

    facebook telegram

    Leave a Reply

    • Required fields are market * .
    • Your email address will not be published.
    • Please ensure your email address is correct, then you will get a notification once a new comment reply.

    Your email address will not be published. Required fields are marked *