Skip to content Skip to sidebar Skip to footer

Sqlite3, Integrityerror: Unique Constraint Failed When Inserting A Value

In order to prevent my database from growing too large I want sqlite only to insert values that has not yet been inserted. I've done some searching and figured the best way to do s

Solution 1:

Change INSERT to INSERT OR IGNORE:

cur.execute('INSERT OR IGNORE INTO oldposts VALUES(?)', [submID])

Solution 2:

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()

Post a Comment for "Sqlite3, Integrityerror: Unique Constraint Failed When Inserting A Value"