0 レビュー
0 回答
php-Doctrine2でテーブル継承を使用して挿入しようとしているDoctrineDBALExceptionUniqueConstraintViolationException
(継承を使用して)このテーブルに新しいデータを挿入しようとしています:
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();
このエラーが発生しました。doctrineは既存の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'
私は教義に何か問題がありますか?
わからない
同様の質問
私たちのウェブサイトで同様の質問で答えを見つけてください。