用户:
神秘蟑螂zl查看:0 回复:5 评论:0 创建时间:2022-06-07T18:45:42
各位大佬,我是一个很弱的新手啊!现在特别想解决一个问题,希望大佬们能指出我的错误
这几天搞个小地图试试,可做到sql表时卡住了,搞了好几个小时还报错,一直找不到原因
sql表这样建的:
async function createTables() {
return await db.sql`CREATE TABLE IF NOT EXISTS "player" (
"userkey" CHAR(16) PRIMARY KEY UNIQUE NOT NULL,
"itemlist" TEXT NOT NULL,
"dengj" INT NOT NULL,
"HP" INT NOT NULL,
"gold" INT NOT NULL,
"EXP" INT NOT NULL
)`;
}
(async function() {
await createTables()
}());
然后插入函数时:
async function saveplayer(entity){
if(entity.player.userKey){
await db.sql`
INSERT INTO "player" (
"userkey",
"itemlist",
"dengj",
"HP",
"gold",
"EXP"
) VALUES (
${entity.player.userKey},
${JSON.stringify(itemList)},
${dj},
${entity.hp},
${gd},
${exp}
)
ON CONFLICT("userkey")
DO UPDATE SET
"itemlist" = excluded."itemlist",
"dengj" = excluded."dengj",
"HP" = excluded."HP",
"gold" = excluded."gold",
"EXP" = excluded."EXP"
`
}
}
结果我给看懵了:
Error: sql error: Error: SQLITE_ERROR: table player has no column named EXP
后面的就省略了,翻译出来说player表内没有名为EXP的列
我明明创建了为什么会没有?
请大佬帮我解答一下,谢谢!
_function_啊这位朋友
表格中数据的名字要一样啊
async function saveplayer(entity){
if(entity.player.userKey){
await db.sql`
INSERT INTO "player" (
"userkey",
"itemlist",
"dengj",
"hp",
"gold",
"exp"
) VALUES (
${entity.player.userKey},
${JSON.stringify(itemList)},
${entity.dengj},
${entity.hp},
${entity.gold},
${entity.exp}
)
ON CONFLICT("userkey")
DO UPDATE SET
"itemlist" = excluded."itemlist",
"dengj" = excluded."dengj",
"hp" = excluded."hp",
"gold" = excluded."gold",
"exp" = excluded."exp"
`
}
}点赞1
评论