Jump to content

Force delete?


dazman

Recommended Posts

Hi, this is more MySQL rather than PHP but i am trying to delete a row, and it has a foreign key field in it. This foreign key is linked to another table which has this as its primary key.

 

I get this error message

Cannot delete or update a parent row: a foreign key constraint fails ()

 

Have I put the FK on the table the wrong way around? I think i added the FK to the child table, rather than the parent. Am i supposed to add it to the parent instead?

Link to comment
https://forums.phpfreaks.com/topic/162501-force-delete/
Share on other sites

Corrected:

Hi, this is more MySQL rather than PHP but i am trying to delete a row, and it has a foreign key field in it. This foreign key is linked to another table which has this as its primary key.

 

I get this error message

Cannot delete or update a parent row: a foreign key constraint fails ()

 

Have I put the FK on the table the wrong way around? I think i added the FK to the parent table, rather than the child. Am i supposed to add it to the child table instead?

 

No rows are coming up.. Im getting an empty set.

 

I ran this statement..

 

select address.Country from address left join country on (address.Country=country.Country) where country.Country is not null and address.Country is null;

 

In this case address is the parent table, this is the record I am trying to delete.

 

country is the other table with the PK in it.

 

What i was using to delete the record was:

DELETE FROM address where Address_ID='ADID00000002';

 

Do i need to add more to this statement?

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/162501-force-delete/#findComment-857689
Share on other sites

My bad here, i had another table which had this row as a FK. i deleted that record, then i could delete this one...

 

Do you know how to do an if statement to run some code if an empty set is returned?

 

if (empty? (mysql_result("SELECT Address_ID FROM address ORDER BY Address_ID")))

{

<code>

}

Link to comment
https://forums.phpfreaks.com/topic/162501-force-delete/#findComment-857699
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.