MySQL: foreign key constraint not enforced -


i have 2 tables follows:

create table customer (   id int not null auto_increment,   name varchar(25),   primary key(id) );  create table `client` (   `id` int not null auto_increment,   `name` varchar(200),   `customer_id` int not null,     primary key(`id`),    index(`customer_id`),    foreign key (`customer_id`) references `customer`(`id`) on update cascade on delete restrict ); 

then ran following:

insert customer (name) values ('customer1'); 

now table customer contains name: customer1, id: 1

then ran this:

insert client (name, customer_id) values ('client of customer1',34); 

it supposed fail, inserted successfully. why that?

this on mysql 5.1 on linux mint.

do show create table customer. it'll show engine used @ end of dumped create table statement. if they're showing myisam, engine doesn't suport foreign keys. fk definitions parsed, otherwise ignored.

to force table inno db, support foren keys, have do

create table ( ... blah blah blah ...) type=innodb;                                        ^^^^^^^^^^^--force innodb type 

Comments

Popular posts from this blog

python - Mongodb How to add addtional information when aggregating? -

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

java - Incorrect order of records in M-M relationship in hibernate -