2015-03-13 9 views
9

sto solo ottenendo un errore strano:SQLite IntegrityError: vincolo UNIQUE non riuscita:

IntegrityError: UNIQUE constraint failed: jumptimes.player_id, jumptimes.map_id, jumptimes.runID 

My SQL QUERY:

t = (playerid, mapid, timeTaken, (time() if not dateOverwrite else dateOverwrite), runID, runLeaveZoneVelocity, EnterZoneVelocity, averageVelocity, time()) 
log("PlayerID: %s | mapid: %s | timeTaken: %s | Date: %s | runID: %s | rlvz: %s | ezv: %s | avgvel: %s | firstFinish: %s" % t) 
execute("INSERT INTO jumptimes (player_id, map_id, duration, date, runID, LeaveZoneVelocity, enterZoneVelocity, averageVelocity, firstFinish) VALUES (?,?,?,?,?,?,?,?,?)", t) 

uscita Log:

17:45:11 - PlayerID: 13 | mapid: 34 | timeTaken: 55.2569999695 | Date: 1426265111.18 | runID: 0 | rlvz: 315.484661963 | ezv: 1159.06484472 | avgvel: 1374.49441131 | firstFinish: 1426265111.18 

La mia struttura del database:

CREATE TABLE IF NOT EXISTS jumptimes (
    id INTEGER PRIMARY KEY AUTO_INCREMENT, 
    player_id INTEGER REFERENCES players ON DELETE CASCADE, 
    map_id INTEGER REFERENCES maps ON DELETE CASCADE, 
    duration REAL, 
    `date` REAL, 
    runID INTEGER, 
    leaveZoneVelocity INTEGER DEFAULT 0, 
    enterZoneVelocity INTEGER DEFAULT 0, 
    averageVelocity INTEGER DEFAULT 0, 
    server INTEGER DEFAULT 0, 
    firstFinish REAL, 
    completions INTEGER DEFAULT 1, 
    UNIQUE (player_id, map_id, runID) 
) 

Come l'argomento dice, nel mese di ottenere sempre SQLite IntegrityError: UNIQUE constraint failed:

risposta

14

La clausola UNIQUE della dichiarazione della vostra tabella afferma che combinazione di ogni riga di player_id, map_id, e runID deve essere univoco. Si sta verificando questo errore perché è già presente una riga nella tabella jumptimes con player_id = 13, map_id = 34 e runID = 0.

Here is a simple SQLFiddle riproduzione dell'errore. Il "vincolo" di cui parla l'errore è la clausola UNIQUE e, se si riuscisse a vedere l'errore completo, sarebbe lo stesso di quello che si ottiene.

Problemi correlati