简体   繁体   中英

Catch double tuples in Sqlite3 (by primary key)

i buil a db with some tables. In every table is min. one primary key. If i insert a new tuple which already exist - TRACEBACK:

self.cursor.execute("INSERT INTO kfehlzeit VALUES (?,?)", row)
sqlite3.IntegrityError: columns TDA, PAY are not unique

This is right, but how can I catch this? Because after this - there are much rows to insert..

Thank you

A simple solution would be to use try/except. It is very generic, but this will allow to continue if it fails to insert the row into table.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM