• mysql IntegrityError: (pymysql.err.IntegrityError) (1062, "Duplicate entry '000001.SZ-2018-07-02' for key 'PRIMARY'")


    IntegrityError: (pymysql.err.IntegrityError) (1062, "Duplicate entry '000001.SZ-2018-07-02' for key 'PRIMARY'")
    [SQL: INSERT INTO stock_daily_basic (ts_code, trade_date, close, turnover_rate, turnover_rate_f, volume_ratio, pe, pe_ttm, pb, ps, ps_ttm, dv_ratio, dv_ttm, total_share, float_share, free_share, total_mv, circ_mv) VALUES (%(ts_code)s, %(trade_date)s, %(close)s, %(turnover_rate)s, %(turnover_rate_f)s, %(volume_ratio)s, %(pe)s, %(pe_ttm)s, %(pb)s, %(ps)s, %(ps_ttm)s, %(dv_ratio)s, %(dv_ttm)s, %(total_share)s, %(float_share)s, %(free_share)s, %(total_mv)s, %(circ_mv)s)]
    [parameters: ({'ts_code': '600230.SH', 'trade_date': '20180702', 'close': 22.84, 'turnover_rate': 3.2284, 'turnover_rate_f': 6.0057, 'volume_ratio': 1.99, 'pe': 7.3318, 'pe_ttm': 7.49, 'pb': 3.1378, 'ps': 2.1296, 'ps_ttm': 2.0831, 'dv_ratio': 0.41, 'dv_ttm': 1.56, 'total_share': 41186.3502, 'float_share': 41186.3502, 'free_share': 22139.6078, 'total_mv': 940696.2386, 'circ_mv': 940696.2386},

    数据表中设置了主键(Primary Key),而主键对应的值是不允许重复的。
    错误提示为:你插入的记录与数据表中原有记录的主键重复了(Duplicate)。所以插入失败。

    注意:检查表中加了”unique=True”属性的字段,在添加记录时是否添加了重复值。

    sqlalchemy给出的错误提示信息:

    https://docs.sqlalchemy.org/en/13/errors.html#error-gkpj

    IntegrityError

    Exception raised when the relational integrity of the database is affected, e.g. a foreign key check fails.

    This error is a DBAPI Error and originates from the database driver (DBAPI), not SQLAlchemy itself.

  • 相关阅读:
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    SpringCloud Alibaba微服务实战一
    Bar:柱状图/条形图
    Pie:饼图
    Gauge:仪表盘
    Funnel:漏斗图
    VSCode+latex引用bibtex参考文献
    因为报表做得太好,我被阎王爷叫走了.....
    ubuntu安装pyCUDA
  • 原文地址:https://www.cnblogs.com/ttrrpp/p/12610654.html
Copyright © 2020-2023  润新知