DDC-1566: Can't create bidirectional OneToMany When a ManyToOne relation exists #1964

Closed
opened 2026-01-22 13:33:57 +01:00 by admin · 4 comments
Owner

Originally created by @doctrinebot on GitHub (Dec 27, 2011).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user agora:

I tried to create a bidirectional relation between two entities (LunchTable and Zone) like this LunchTable <--- n-1 ---> Zone.
The relation ManyToOne in LunchTable work perfectly. But the OneToMany doesn't work : when i try to insert into the DB a LunchTable row, I have : integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (supproject.lunchtable, CONSTRAINT FK*B76A375B9F2C3FAB FOREIGN KEY (zone*id) REFERENCES Zone (id) ON DELETE CASCADE)

My Zone entity is in relation with another one called Restaurant ( like this : Zone <--- 1-n ---> Restaurant )
These two relations work perfectly.

The problem append when i set up the OneToMany relation in the Zone entity.

In order to solve this problem, i have to redo the relation with a mysql client or phpmyadmin, and it work.

My files : http://pastebin.com/TNC06Ffg

Originally created by @doctrinebot on GitHub (Dec 27, 2011). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user agora: I tried to create a bidirectional relation between two entities (LunchTable and Zone) like this LunchTable <--- n-1 ---> Zone. The relation ManyToOne in LunchTable work perfectly. But the OneToMany doesn't work : when i try to insert into the DB a LunchTable row, I have : integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`supproject`.`lunchtable`, CONSTRAINT `FK*B76A375B9F2C3FAB` FOREIGN KEY (`zone*id`) REFERENCES `Zone` (`id`) ON DELETE CASCADE) My Zone entity is in relation with another one called Restaurant ( like this : Zone <--- 1-n ---> Restaurant ) These two relations work perfectly. The problem append when i set up the OneToMany relation in the Zone entity. In order to solve this problem, i have to redo the relation with a mysql client or phpmyadmin, and it work. My files : http://pastebin.com/TNC06Ffg
admin added the Bug label 2026-01-22 13:33:57 +01:00
admin closed this issue 2026-01-22 13:34:02 +01:00
Author
Owner

@doctrinebot commented on GitHub (Dec 27, 2011):

Comment created by agora:

I investigate about the problem and i find something : if i replace my Zone entity by a Area entity (with the same code except some adaptations) it work.

So, I put on a reservation of the word 'Zone' in the source code of Doctrine (or maybe Symfony ?)

@doctrinebot commented on GitHub (Dec 27, 2011): Comment created by agora: I investigate about the problem and i find something : if i replace my Zone entity by a Area entity (with the same code except some adaptations) it work. So, I put on a reservation of the word 'Zone' in the source code of Doctrine (or maybe Symfony ?)
Author
Owner

@doctrinebot commented on GitHub (Jan 16, 2012):

Comment created by @guilhermeblanco:

There's no restriction on Doctrine side for word "Zone".

@doctrinebot commented on GitHub (Jan 16, 2012): Comment created by @guilhermeblanco: There's no restriction on Doctrine side for word "Zone".
Author
Owner

@doctrinebot commented on GitHub (Mar 14, 2012):

Comment created by @beberlei:

The error message says whats wrong. Zone_id to be set does not seem to exist in The Zone table. I would guess your Zone entity has a wrong mapping, either wrong @Table or missing @Entity or something.

@doctrinebot commented on GitHub (Mar 14, 2012): Comment created by @beberlei: The error message says whats wrong. Zone_id to be set does not seem to exist in The Zone table. I would guess your Zone entity has a wrong mapping, either wrong @Table or missing @Entity or something.
Author
Owner

@doctrinebot commented on GitHub (Mar 14, 2012):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Mar 14, 2012): Issue was closed with resolution "Invalid"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1964