views:

27

answers:

1

Hello all!

http://img839.imageshack.us/img839/8241/stackoverflow.png

I created a new databese. There are 2 tables class and teacher. There is a field class_leader in the table class related with teacher_id from teacher. [1]

In PHPMyAdmin relationship looks like: [2]

Table teacher contains some records. [3]

When I add new records at table class: [4]

Why IDs in class_leader are doubled? [5]

What does it means? What should i do?

Thanks for your help.

A: 

Because the relationship between class and teacher is many-to-one. It's normal to have duplicate ids in the class_leader column.

Sorry, I did not see the screenshot. If you don't have the class_leader field as unique, it's normal to have duplicate ids. Make it a column with unique values and you'll be fine.

Vasileios Lourdas
Thanks for answer. But i'm set relationship one-to-one, you may see it at first part of screenshot.
WarLock
I set `class_leader` as UNIQUE value, but nothing changes.
WarLock
It would help if you had some piece of code to see how you do the insertion.
Vasileios Lourdas
INSERT INTO `school`.`class` (`class_id` ,`class_number` ,`class_letter` ,`class_quantity` ,`class_shedule` ,`class_leader` )VALUES (NULL , '5', 'C', '25', '17', '1'); -------- In PHPMyAdmin it looks like http://img684.imageshack.us/img684/9715/image024.png
WarLock
If you set the class_leader column to be unique, it would fail with an error, since there are duplicate values. Can you please issue a __show create table__ command for both tables and attach the output here?
Vasileios Lourdas
http://dl.dropbox.com/u/3094974/stackoverflow.sql
WarLock
In the class table, you have two indexes on the class_leader column. Delete the non-unique one.
Vasileios Lourdas
I did it. But nothing changes. May be leave everything as is? It seems that everything works.
WarLock
I have a idea that it is just PHPMyAdmin error. The databse is correct. What you think about that?
WarLock