L
L
LittleFatNinja2015-04-16 23:17:03
SQL
LittleFatNinja, 2015-04-16 23:17:03

SQLite Why FOREIGN KEY vseravno allows to interpose a nonexistent field of other table?

CREATE TABLE category (
  name TEXT NOT NULL
);

INSERT INTO category(name) VALUES
  ('food')	
;

CREATE TABLE item (
  id INTEGER PRIMARY KEY,
  name TEXT NOT NULL,
  category TEXT NOT NULL,
  FOREIGN KEY (category) REFERENCES category(name)
);

INSERT INTO item(name, category) VALUES
  ('cookie', 'ololo') -- ok. no error
;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xibir, 2015-04-16
@LittleFatNinja

Foreign keys in sqlite are disabled by default, they must be manually enabled. Everything is written
here https://www.sqlite.org/foreignkeys.html#fk_enable

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question