I deployed my projet on a new server and the error "SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails" shows up when i try to INSERT a class with inheritance :
/**
* @ORM\Table(name="prosante")
* @ORM\Entity
*/
class ProSante extends Base
{
/**
* @ORM\Column(type="string")
*/
protected $firstName;
}
/**
* @ORM\Table(name="base")
* @ORM\Entity(repositoryClass="Test\MyBundle\Entity\BaseRepository")
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="discr", type="string")
* @ORM\DiscriminatorMap({"base" = "Base",
* "prosante" = "ProSante",
* "pharmacie" = "Pharmacie"})
*/
abstract class Base
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
}
Log :
[2012-06-11 15:42:46] doctrine.DEBUG: INSERT INTO base (name) VALUES (?) ({"1":"Blabla"}) [] []
[2012-06-11 15:42:46] doctrine.DEBUG: INSERT INTO prosante (id, firstname) VALUES (?, ?) ({"1":"0","2":"PATRICK"}) [] []
I don't know what to do since the error doesn't show up when i do the same INSERT on localhost.
EDIT I check "SELECT LAST_INSERT_ID();" after manualy insert a new "Base" into my database, its doesn't return 0, i don't understand.
SOLUTION It was a driver problem, i change it and it works.
It appears doctrine is interpreting "Base" as its own table. I think what you want to achieve here is to have your Base class as a mapped super class.
To do this simply annotate it as:
@MappedSuperclass
And then you can safely extend it into your other Entities..
http://docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/reference/inheritance-mapping.html#mapped-superclasses