亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么在 sql.js 中出現“NOT NULL 約束失敗”錯誤?

為什么在 sql.js 中出現“NOT NULL 約束失敗”錯誤?

白衣非少年 2023-07-14 15:40:15
sql.js 我正在嘗試使用https://github.com/sql-js/sql.js在 html 網頁中創建一個包含以下列的表。<script src="sql.js"></script><script>     var data;     config = {          locateFile: filename => `sql.js`     }</script><script>initSqlJs(config).then(function (SQL) {    var db = new SQL.Database();    db.run(`CREATE TABLE notes (        id              integer primary key,   /* 0 */        guid            text not null,         /* 1 */        mid             integer not null,      /* 2 */        mod             integer not null,      /* 3 */        usn             integer not null,      /* 4 */        tags            text not null,         /* 5 */        flds            text not null,         /* 6 */        sfld            integer not null,      /* 7 */        csum            integer not null,      /* 8 */        flags           integer not null,      /* 9 */        data            text not null          /* 10 */    );`)    db.run( `INSERT INTO notes (id, guid, mid, mod, usn, tags, flds, sfld, csum, flags, data)    VALUES (?, ?, ?, ?, ?, ?, ?, ?, 0, 0, '')`, 123,"abcdef", 12345, 56789, -1, "tags", "hi", 0);});</script>但出現以下錯誤sql.js:89 Uncaught Error: NOT NULL constraint failed: notes.guid    at c.handleError (sql.js:89)    at a.step (sql.js:80)    at c.run (sql.js:86)    at <anonymous>:1:5可以采取什么措施來消除錯誤?謝謝
查看完整描述

1 回答

?
青春有我

TA貢獻1784條經驗 獲得超8個贊

可能是因為您提供的值run應該位于單個數組中,而不是作為多個參數傳遞。


<script src="sql.js"></script>

<script>

     var data;

     config = {

          locateFile: filename => `sql.js`

     }

</script>

<script>

initSqlJs(config).then(function (SQL) {

    var db = new SQL.Database();

    db.run(`CREATE TABLE notes (

        id              integer primary key,   /* 0 */

        guid            text not null,         /* 1 */

        mid             integer not null,      /* 2 */

        mod             integer not null,      /* 3 */

        usn             integer not null,      /* 4 */

        tags            text not null,         /* 5 */

        flds            text not null,         /* 6 */

        sfld            integer not null,      /* 7 */

        csum            integer not null,      /* 8 */

        flags           integer not null,      /* 9 */

        data            text not null          /* 10 */

    );`)


    db.run(

        `INSERT INTO notes (id, guid, mid, mod, usn, tags, flds, sfld, csum, flags, data)

    VALUES (?, ?, ?, ?, ?, ?, ?, ?, 0, 0, '')`, 

        [123,"abcdef", 12345, 56789, -1, "tags", "hi", 0]

    );

});

</script>


查看完整回答
反對 回復 2023-07-14
  • 1 回答
  • 0 關注
  • 131 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號