V
V
Vyacheslav Alekseevich2018-03-05 16:04:15
PHP
Vyacheslav Alekseevich, 2018-03-05 16:04:15

How to create a one to many relationship in phpMyAdmin?

Good afternoon!
Interested in the question, how to create a relationship between tables type "one to many"?

I have tables "Parents", "Children", "Photos" and "Notes", I want to make sure that parents have many children, and children have many photos and notes, but if I create two children for one parent, on phpMyAdmin starts to swear at me:

Duplicate entry '*' for key 'Parent'


5a9d3f4a968d6315923088.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Tsvetkov, 2018-03-05
@Slavchik

Didn't they tell you "about it" in school? The child has two parents.

Duplicate entry '*' for key 'Parent'
Remove uniqueness from this key.
And one more note. Do not indicate age in the table . Will lose relevance next year. You need to indicate the date of birth , and calculate the age .
Formula for MS SQL (with date of death, you can immediately substitute the current date):
CAST( DATEDIFF( Year, BirthDay, ISNULL( DeathDay, GETDATE())) + ( SIGN ( DATEDIFF ( DAY, BirthDay, DATEADD ( YEAR, YEAR( BirthDay ) - YEAR( ISNULL( DeathDay, GETDATE()) ), ISNULL( DeathDay, GETDATE())))) - 1 ) / 2 AS VARCHAR)

S
Semyon, 2018-03-05
@pnn

In the table of children, make a key on two fields, parent id and parent_name

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question