SQL SQLite IntegrityError:唯一约束失败:
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29037793/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQLite IntegrityError: UNIQUE constraint failed:
提问by Fragkiller
I am just getting an weird error:
我刚刚收到一个奇怪的错误:
IntegrityError: UNIQUE constraint failed: jumptimes.player_id, jumptimes.map_id, jumptimes.runID
My SQL QUERY:
我的 SQL 查询:
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)
Log output:
日志输出:
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
My Database structure:
我的数据库结构:
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)
)
As the topic says, im always getting SQLite IntegrityError: UNIQUE constraint failed:
正如主题所说,我总是得到 SQLite IntegrityError: UNIQUE constraint failed:
回答by Paul Griffin
The UNIQUE
clause of your table's declaration states that every row's combination of player_id
, map_id
, and runID
must be unique. You are getting this error because there is already a row in the jumptimes
table withplayer_id = 13
, map_id = 34
, and runID = 0
.
在UNIQUE
你的表声明的条款规定,每一行的组合player_id
,map_id
和runID
必须是唯一的。您收到此错误,因为已经有在一排jumptimes
桌子player_id = 13
,map_id = 34
和runID = 0
。
Here is a simple SQLFiddlereproducing the error. The "constraint" the error is talking about is the UNIQUE clause, and if you could see the full error, it would be the same as the one you're getting.
这是一个简单的 SQLFiddle重现错误。错误所谈论的“约束”是 UNIQUE 子句,如果您能看到完整的错误,它将与您得到的错误相同。