I have a problem with a MySQL database. I want to delete user about id=1 using this query "delete from user where user_id =1
".
At this moment should be delete a user, and also every his post from table "post". The problem is that user is deleted, but his post in table "post" not delete. EDIT: I try to create a table using InnoDB engine, but show me error.
CREATE TABLE `post` (
`post_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`comment` varchar(300) COLLATE utf8_polish_ci NOT NULL,
`date_to_add` date NOT NULL,
`time_to_add` time NOT NULL,
FOREIGN KEY (`user_id`) REFERENCES user(`user_id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci;
CREATE TABLE `user` (
`user_id` int(11) NOT NULL,
`login` varchar(20) COLLATE utf8_polish_ci NOT NULL,
`password` tinytext COLLATE utf8_polish_ci NOT NULL,
`first_name` varchar(30) COLLATE utf8_polish_ci NOT NULL,
`last_name` varchar(40) COLLATE utf8_polish_ci NOT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci;