django1.11.11 bulk_create报错 Duplicate重复插入已存在的错误

pip3 show django
cd /home/yuntao/.local/lib/python3.5/site-packages/django
vi db/models/sql/compiler.py

:?def as_sql

# result = ['INSERT INTO %s' % qn(opts.db_table)]
# modify by yuntaoWei 2020-02-10 resolve insert into or bulk create duplicate ignore by futeaure 'ignore_conflicts'
result = ['INSERT %s INTO %s' % (('', 'IGNORE')[getattr(self.query.model or opts.concrete_model, 'ignore_conflicts', False)==True], qn(opts.db_table))]

#这个时候,便可以通过给模型类添加ignore_conflicts=True的类属性来控制其只是warning而不是终止程序

你可能感兴趣的:(笔记)