Edit: I did what @MichaelHirschler and @MayaShah suggested and it solved the problem and it allow me to create a Doctrine Migration file using the doctrine:migration:diff command, but when I tried to migrate these changes to the database with doctrine:migration:migrate the following errors appeared.
Migration 20170325192546 failed during Execution. Error An exception occurred while executing 'ALTER TABLE business ADD CONSTRAINT FK_8D36E3844FFE0C3 FOREIGN KEY (client_email) REFERENCES client (clientEmail)':
SQLSTATE[HY000]: General error: 1005 Can't create table 'eship_case.#sql-81c_e' (errno: 150)
[Doctrine\DBAL\Exception\DriverException] An exception occurred while executing 'ALTER TABLE business ADD CONSTRAINT FK_8D36E3844FFE0C3 FOREIGN KEY (client_email) REFERENCES client (clientEmail)':
I understand that this is a MySQL error but I thought that Doctrine would take care of the migration, so when it didn't I don't know how to fix it. I could do the schema manually on MySQL to fix this but I dont know how would that affect the ORM schema in Symfony. Sorry for bothering, I'm new to PHP and therefore new to Symfony and Doctrine.
Original Post: I'm doing a web application using Symfony Framework with MySQL as the database. I'm using doctrine to do the ORM to map the database. But when I'm trying to update the schema of the database to include the foreign keys, the following error appears: 1 I don't really understad the error and I will appreciate any help anyone can give me.
Here's the code of both classes. The primary key of Client is clientEmail and I want to make a relation with that key to the business entity. I know there might be some documentation missing but I'm trying to fix this error before moving to that. The classes are longer but I only posted the areas that could be causing the problem.
Business Class:
<?php
/**
* @ORM\Entity
* @ORM\Table(name="business")
*/
class Business
{
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
private $businessId;
/**
* @ORM\Column(type="string")
*/
private $name;
/**
* @ORM\Column(type="string")
*/
private $stage_Of_Development;
//Relations
/**
* @ORM\ManyToOne(targetEntity="Client")
*/
private $client;
//Getters and Setters
/**
* @return mixed
*/
public function getClient()
{
return $this->client;
}
/**
* @param mixed $client
*/
public function setClient(Client $client)
{
$this->client = $client;
}
}
Client Class:
<?php
/**
* @ORM\Entity
* @ORM\Table(name="client")
*/
class Client
{
/**
* @ORM\ID
* @ORM\Column(type="string")
*/
private $clientEmail;
/**
* @return mixed
*/
public function getClientEmail()
{
return $this->clientEmail;
}
/**
* @param mixed $clientEmail
*/
public function setClientEmail($clientEmail)
{
$this->clientEmail = $clientEmail;
}
}