码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2020-04-01 10:33:38      阅读:358      评论:0      收藏:0      [点我收藏+]

标签:ram   ocs   添加记录   free   his   reference   try   share   nat   

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.

 

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

标签:ram   ocs   添加记录   free   his   reference   try   share   nat   

原文地址:https://www.cnblogs.com/ttrrpp/p/12610654.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!