Kostas Thanasis
Kostas Thanasis

Reputation: 378

Foreign key constraint does not apply

I have defined a foreign key. To check it, i insert wrong values to the table that has the foreign key. No error were printed and the values were added succefully. I do not know if i am running some old version of sqlite3 or something like that, i am completely new to this area.

create table ref(value1 int ,value2,primary key(value1));

create table for(value1 int,value3 int,primary key(value3),foreign key(value1)references ref(value1));

insert into for values (1,1);

This was added succefully.

Upvotes: 1

Views: 553

Answers (1)

forpas
forpas

Reputation: 164214

Foreign key constraints are disabled by default as it is explained here: SQLite Foreign Key Support.
To enable them execute first:

PRAGMA foreign_keys = ON;

See the demo.

Upvotes: 3

Related Questions