sql - Postgresql delete on cascade -


i have 2 tables. device , device_config. device table has following columns:

device_id config_id bla bla2 foo bar 

and device_config has following columns

id foo bar 

as can predict, config_id on device table foreign key referencing id column on device_config have added constraint on device table.

alter table device add constraint device_config_id_fk foreign key (config_id) references device_config (id) match simple on update no action on delete cascade; 

but way, when row in device_config deleted, corresponding row on device table deleted. want opposite. when device deleted, want corresponding entry in device_config deleted. how can achieve this?

then change logic. device table wont have *config_id* , device_config have *device_id*. relation 1 device may have many device_configs.

then

alter table device_config add constraint device_config_fk foreign key (device_id) references config (device_id) match simple on update no action on delete cascade; 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -