Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Alphy Gacheru's avatar

SQL query to update a column to be foreignId and onDelete Cascade

I'm working on a live laravel website on cPanel and I'd like to update the user_id column on the properties table to be foreignId and onDelete Cascade.

I have tried the following:

ALTER TABLE properties
ADD CONSTRAINT fk_properties_user
FOREIGN KEY (user_id)
REFERENCES users(id)
ON DELETE CASCADE;

But it's not working(deleting a user doesn't delete its associated property) and I'm getting the following response when I execute the command above:

MySQL returned an empty result set (i.e. zero rows). (Query took 0.1913 seconds.)

ALTER TABLE properties ADD CONSTRAINT fk_properties_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
0 likes
5 replies
vincent15000's avatar

It should work.

Have you checked with phpmyadmin if the foreign key has been added ?

Alphy Gacheru's avatar

@vincent15000 Hi, sorry I missed your notification. I used another alternative. For future reference, how do I confirm that in the phpmyadmin.

1 like
vincent15000's avatar

@Alphy Gacheru You have to check the structure of the table in phpmyadmin and search for the foreign keys and their indexes.

1 like
Alphy Gacheru's avatar

I was unable to solve it in the phpMyAdmin, solved it using another alternative, and asked for your explanation for future reference.

1 like

Please or to participate in this conversation.