So the scenario is this:

I create a group with a form, stored in test\_groups\_tb, then with another form enter user ids to attach them to the group and they are stored in group\_association\_tb with a structure like so:

`group_id | user_id`

I am very new to MySQL and more so Foreign Key relationships, so I tried to set up a relationship on group\_association\_tb which was basically, if the group was deleted, delete all records of that group from group\_association\_tb.

now what Is happening since applying this is the group is stored fine. I can add students manually fine, but when I try adding them by importing a csv it doesn't like it.

here is the queries (i know its not efficient querying every iteration):

```
while($row = mysql_fetch_assoc($result))
    {
        $sql = "INSERT INTO group_association_tb (group_id, user_id)VALUES('$group','".$row[user_id]."')";
        mysql_query($sql) or die(header("Location:error.php"));
    } 

```

here is the error i get:

```
Cannot add or update a child row: a foreign key constraint fails (`ece70141/group_association_tb`, CONSTRAINT `group_association_tb_ibfk_1` FOREIGN KEY (`group_id`) REFERENCES `test_groups_tb` (`group_id`) ON DELETE CASCADE)

```

could somebody explain what the problem is here.

many thanks,