Verify if you have a foreign key and if not delete it. Codeigniter

-1

I have my table proveedor with a field called status 1 active 0 removed, I only update when removing

delete:

$data => array('status' => 0);
$this->db->update('proveedor',$data);

Try changing the update to delete

$this->db->delete('proveedor',$id);

The problem is that when there is data related to that provider, it marks me an error. There will be some way of knowing if that provider is related to another table, and if so just change status otherwise you can use delete and thus avoid unnecessary records.

The restrictions I have in my BDD is

ON DELETE restrict, ON UPDATE cascade
    
asked by DoubleM 02.05.2018 в 01:45
source

1 answer

0

RESTRICT: It is the default behavior, which prevents modifications that undermine the referential integrity.

A record can be deleted when there is no related record in the table with which it is related, in this case when using DELETE you are violating that restriction therefore it will not delete it.

A RESTRICT in MySQL is basically the same as a NO ACTION , try using SET NULL since with this what ara is to set to NULL the value of the secondary key when the record is deleted in the main table or the value of the referenced field is modified.

It should be mentioned that with this data will remain in the air, that is, you will eliminate the data from your main table, but those of the referenced tables will continue to exist with the NULL value and basically remain in the air.

    
answered by 03.05.2018 в 00:00