我正在尝试在此表上插入新数据(使用继承):
Entity\AbstractSurveyAnswer:
type: entity
table: survey_answers
inheritanceType: JOINED
discriminatorColumn:
name: type_class
type: string
discriminatorMap:
database: SurveyDatabaseAnswer
client_text: SurveyClientTextAnswer
client_number: SurveyClientNumberAnswer
client_date: SurveyClientDateAnswer
id:
id:
type: integer
generator:
strategy: AUTO
manyToOne:
client:
targetEntity: Entity\Client
joinColumn:
name: id_client
nullable: false
referenceColumnName: id
survey:
targetEntity: Entity\AbstractSurvey
joinColumn:
name: id_survey
nullable: false
referenceColumnName: id
和
Entity\SurveyDatabaseAnswer:
type: entity
table: survey_database_answers
indexes:
id:
columns: [id, id_answer]
manyToOne:
answer:
targetEntity: Entity\Answer
joinColumn:
name: id_answer
nullable: false
referenceColumnName: id
我以这种方式更新表,并且它起作用(有一些省略的代码和一些诸如flush的学说功能封装在另一个类上)
$updated_answer = new SurveyDatabaseAnswer();
$updated_answer->setId($result[0]);
$updated_answer->setClient($client);
$updated_answer->setSurvey($survey);
$updated_answer->setAnswer($answer);
$storage->merge($updated_answer);
$storage->flush();
但是如果我尝试插入新行
$updated_answer = new SurveyDatabaseAnswer();
$updated_answer->setClient($client);
$updated_answer->setSurvey($survey);
$updated_answer->setAnswer($answer);
$storage->persist($updated_answer);
$storage->flush();
我收到此错误,教义试图插入和存在的ID
Type: Doctrine\DBAL\Exception\UniqueConstraintViolationException
Message: An exception occurred while executing 'INSERT INTO survey_database_answers (id, id_answer) VALUES (?, ?)' with params [7438572, 1888]: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '7438572' for key 'PRIMARY'
我在教义上犯错了吗?