使用php app / console doctrine时出现以下错误:schema:update --force。
[Doctrine\DBAL\DBALException] An exception occurred while executing 'ALTER TABLE profiles ADD CONSTRAINT FK_8B30853036802B0F FOREIGN KEY (participantid) REFERENCES participants (id )': SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`smartplan_dev`.`#sql-518_60`, CONSTRAINT `FK_8B30853036802B0F` FOREIGN KEY (`participantid`) REFERENCES `participants` (`id`))
[PDOException]
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update
a child row: a foreign key constraint fails (smartplan_dev
.#sql-518_60
,
CONSTRAINTFK_8B30853036802B0F
FOREIGN KEY (participantid
) REFERENCES
participants
(id
))
如果有一个映射失败的实例,是否会发生此错误?我可以看到这是有问题的,因为我的客户喜欢使用mysql workbench直接编辑。有没有办法可以跳过失败的行而不会使整个更新失败。
这是我的实体文件。 (个人资料部分完成)。
namespace classes\classBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * profiles * * @ORM\Table() * @ORM\Entity */ class profiles { /** * * @ORM\ManyToOne(targetEntity="participants", inversedBy="profiles") * @ORM\JoinColumn(name="participantid", referencedColumnName="id") */ public $participant;//participant variable /** * @ORM\OneToMany(targetEntity="profilesBeneficiaries", mappedBy="profile") * */ public $beneficiaries;//beneficiaries array variable public $contributions; //contributions variable public $investments; //investments array variable public $retirementNeeds; //retirementNeeds variable public $riskProfile;//riskProfile variable /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ public $id; /** * @var integer * * @ORM\Column(name="participantid", type="integer") */ public $participantid; /** * @var integer * * @ORM\Column(name="userid", type="integer") */ public $userid; /** * @var string * * @ORM\Column(name="planid", type="integer") */ public $planid; /** * @var string * * @ORM\Column(name="planName", type="string", length=255) */ public $planName; /** * @var string * * @ORM\Column(name="currentBalance", type="float",length = 255) */ public $currentBalance; /** * @var string * * @ORM\Column(name="beneficiaryStatus", type="text",length = 65535) */ public $beneficiaryStatus; /** * @var string * * @ORM\Column(name="investmentsStatus", type="text",length = 65535) */ public $investmentsStatus; /** * @var string * * @ORM\Column(name="realignmentStatus", type="text",length = 65535) */ public $realignmentStatus; /** * @var string * * @ORM\Column(name="contributionsStatus", type="text",length = 65535) */ public $contributionsStatus; /** * @var string * * @ORM\Column(name="catchupContributionStatus", type="text",length = 65535) */ public $catchupContributionStatus; /** * @var string * * @ORM\Column(name="annualSalary", type="float",length = 255) */ public $annualSalary; /** * @var string * * @ORM\Column(name="retireAge", type="integer") */ public $retireAge; /** * @var string * * @ORM\Column(name="preTaxSavingRate", type="float",length = 255) */ public $preTaxSavingRate; /** * @var string * * @ORM\Column(name="postTaxSavingRate", type="float",length = 255) */ public $postTaxSavingRate; /** * @var string * * @ORM\Column(name="rothTaxSavingRate", type="float",length = 255) */ public $rothTaxSavingRate; /** * @var string * * @ORM\Column(name="mStarContribution", type="text",length = 65535) */ public $mStarContribution; /** * @var string * * @ORM\Column(name="mStarStatus", type="text",length = 65535) */ public $mStarStatus; /** * @var string * * @ORM\Column(name="smart401kStatus", type="text",length = 65535) */ public $smart401kStatus; /** * @var string * * @ORM\Column(name="reportDate", type="datetime") */ public $reportDate; /** * @var string * * @ORM\Column(name="profileId", type="string", length = 50) */ public $profileId; /** * @var string * * @ORM\Column(name="acceptedAdvice", type="text",length = 65535) */ public $acceptedAdvice; /** * @var string * * @ORM\Column(name="ACAOptOutStatus", type="text",length = 65535) */ public $ACAOptOutStatus; /** * @var string * * @ORM\Column(name="profilestatus", type="smallint") */ public $profilestatus; /** * @var string * * @ORM\Column(name="availability", type="string",length = 250) */ public $availability; /** * @var string * * @ORM\Column(name="clientCalling", type="string",length = 50) */ public $clientCalling; /** * @var string * * @ORM\Column(name="mstarQuit", type="smallint" ) */ public $mstarQuit; /** * @var string * * @ORM\Column(name="rkdData", type="text",length = 65535 ) */ public $rkdData; /** * @var string * * @ORM\Column(name="welcomeVideo", type="string",length = 63 ) */ public $welcomeVideo; /** * @var string * * @ORM\Column(name="planBasicVideo", type="string",length = 127 ) */ public $planBasicVideo; /** * @var string * * @ORM\Column(name="uniqid", type="string",length = 63 ) */ public $uniqid; /** * @var string * * @ORM\Column(name="migration", type="smallint" ) */ public $migration; }
namespace classes\classBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * participants * * @ORM\Table() * @ORM\Entity */ class participants { /** * @ORM\OneToMany(targetEntity="profiles", mappedBy="participant") * */ public $profiles;//array of profiles /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ public $id; /** * @var string * * @ORM\Column(name="firstName", type="blob", length = 127) */ public $firstName; /** * @var string * * @ORM\Column(name="lastName", type="blob", length = 127) */ public $lastName; /** * @var string * * @ORM\Column(name="legalName", type="blob", length = 255) */ public $legalName; /** * @var string * * @ORM\Column(name="address", type="blob", length = 255) */ public $address; /** * @var string * * @ORM\Column(name="city", type="string", length = 50) */ public $city; /** * @var string * * @ORM\Column(name="state", type="string", length = 50) */ public $state; /** * @var string * * @ORM\Column(name="zip", type="string", length = 10) */ public $zip; /** * @var string * * @ORM\Column(name="maritalStatus", type="blob", length = 63) */ public $maritalStatus; /** * @var string * * @ORM\Column(name="employmentDate", type="blob", length = 127) */ public $employmentDate; /** * @var string * * @ORM\Column(name="birthDate", type="blob", length = 127) */ public $birthDate; /** * @var string * * @ORM\Column(name="employeeId", type="blob", length = 255) */ public $employeeId; /** * @var string * * @ORM\Column(name="email", type="blob", length = 255) */ public $email; /** * @var string * * @ORM\Column(name="phone", type="string",length = 50) */ public $phone; }
答案 0 :(得分:2)
是的,它失败了,因为架构中的条目或条目数违反了您的外键约束。这与您的映射或学说ORM无关。这是一个sql返回的错误,并且你不能强制它跳过任何失败的条目,因为doctrine只是数据库的一个抽象层。在任何情况下,这都是外键的重点,以保持数据的完整性。
对不起,但我觉得我有责任告诉您,找到那些违反您约束条件的表条目并据此处理它们符合您的最佳利益。下次你的客户尝试对数据库做任何事情时,除非他知道他究竟应该做的是什么,否则他将无法做到这一点。