It should work.
Have you checked with phpmyadmin if the foreign key has been added ?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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
Please or to participate in this conversation.