Answer the question
In order to leave comments, you need to log in
How to make a connection in MySQL?
Hello!
I read articles on the Internet and watched video tutorials, but I can’t create a link between tables
, so let’s say there are two tables
1 - post (id, status, date)
2 - post_content (id, parent_id, language, name, content)
when deleting a post I need to delete it all the contents that are in different languages,
how can I do this?
I have MySQL version 5.7
in phpMyAdmin how to do it? or you need a request
in my opinion I didn’t understand very well link them
Answer the question
In order to leave comments, you need to log in
If I understood correctly, then here you have a one-to-many relationship, the `post_content`.`parent_id` field points to `post`.`id`.
In order to create such a relationship (foreign key, FOREIGN KEY) in MySQL, you first need to make sure that both of these fields are of the same type and size and that there are no values in the `post_content`.`parent_id` column that are missing in `post`.`id `.
Then you need to create the connection itself
ALTER TABLE `post_content`
ADD CONSTRAINT FOREIGN KEY `fk_parent_id` (`parent_id`)
REFERENCES `post` (`id`)
ON DELETE CASCADE;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question