这是我在symfony 3.4中更新架构时遇到的错误。 当我将第二个类中的referencedColumnName更改为第一个类的id时,它不会出错。但当我把它改成" costmodelinternal_name"第一个类中的变量,它会给我以下错误。
In AbstractMySQLDriver.php line 121:
An exception occurred while executing 'ALTER TABLE cost_model_internal ADD CONSTRAINT FK_F59CC1232B401EC6 FOREIGN K
EY (costmodelinternal_name) REFERENCES bonus_calculation_1 (costmodelinternal_name)':
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
In PDOConnection.php line 106:
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
In PDOConnection.php line 104:
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
doctrine:schema:update [--complete] [--dump-sql] [-f|--force] [--em [EM]] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>
这是类相关字段(一对多)关系
class BonusCalculation1
{
/**
* @ORM\OneToMany(targetEntity="CostModelInternal", mappedBy="bonus_calculation1")
*/
private $cost_model_internals;
public function __construct() {
$this->cost_model_internals = new ArrayCollection();
}
}
class CostModelInternal
{
/**
* @ORM\ManyToOne(targetEntity="BonusCalculation1", inversedBy="cost_model_internals")
* @ORM\JoinColumn(name="costmodelinternal_name", referencedColumnName="costmodelinternal_name")
*/
private $bonus_calculation1;
}
提前感谢您的帮助
答案 0 :(得分:0)
实际上我正在尝试使用没有主键属性来构建关系。在学说中不允许这样做