sqlite3, IntegrityError: UNIQUE constraint failed when inserting a value
Change INSERT
to INSERT OR IGNORE
:
cur.execute('INSERT OR IGNORE INTO oldposts VALUES(?)', [submID])
Change "INSERT" to "INSERT OR REPLACE" it's better...
Update_Table = """INSERT OR REPLACE INTO station_statusDB VALUES(?, ?, ?, ?);"""with sql.connect(station_statusDB) as Conn: print("Connected to:", station_statusDB) Conn.execute(New_Station_Table) while Client_Flag != 0: print("Updating Station Database...") Conn.execute(Update_Table, (ClientID, Client_date, Client_Alarm, Client_Water)) print("Done!, Saving...") Conn.commit()