【问题标题】:SQLite Foreign Key Constraint Not Throwing ErrorSQLite 外键约束不抛出错误
【发布时间】:2020-12-17 04:12:17
【问题描述】:

我正在关注本指南:https://sqlite.org/foreignkeys.html

但是当我自己尝试时,它并没有报错:

sqlite> CREATE TABLE artist(
   ...>   artistid    INTEGER PRIMARY KEY,
   ...>   artistname  TEXT
   ...> );
sqlite> CREATE TABLE track(
   ...>   trackid     INTEGER,
   ...>   trackname   TEXT,
   ...>   trackartist INTEGER,
   ...>   FOREIGN KEY(trackartist) REFERENCES artist(artistid)
   ...> );
sqlite> INSERT INTO track (trackid, trackname, trackartist) VALUES (1, 'Me', 1);
sqlite>

【问题讨论】:

    标签: sql sqlite foreign-keys


    【解决方案1】:

    必须通过命令PRAGMA foreign_keys = ON;启用外键支持

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-28
      • 1970-01-01
      • 2014-01-17
      • 1970-01-01
      • 2021-07-23
      • 1970-01-01
      相关资源
      最近更新 更多