I'm having trouble with foreign keys in doctrine. I have a "User"-table and a "Orders"-table. Now I want to have a foreign key from userID in the orders-table to the id in the user-table. The orders-entity looks like:
<?php namespace Application\TestBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Table( * name="Orders", * options={"collate"="utf8_general_ci", * "charset"="utf8", * "engine"="InnoDB" * } * ) * @ORM\Entity(repositoryClass="Application\TestBundle\Entity\OrdersRepository") */ class Orders { /** * @var integer * * @ORM\Column( * name="id", * unique=true, * type="integer", * options={"unsigned"=true} * ) * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var integer * * @ORM\Column( * name="userID", * type="integer", * nullable=false, * options={"unsigned"=true} * ) * @ORM\OneToOne(targetEntity="User") * @ORM\JoinColumn(name="userID", referencedColumnName="id") */ private $userID; // ... } The user-entity looks like:
<?php namespace Application\TestBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Table( * name="User", * options={"collate"="utf8_general_ci", * "charset"="utf8", * "engine"="InnoDB" * } * ) * @ORM\Entity(repositoryClass="Application\TestBundle\Entity\UserRepository") */ class User { /** * @var integer * * @ORM\Column( * name="id", * unique=true, * type="integer", * options={"unsigned"=true} * ) * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; // ... } Unfortunately no foreign key will be set. It is not in the SQL-query. What am I doing wrong?