我有一个大数据库可导入(约350 MB)。尝试使用命令行mySQL导入此数据库时,我有一个错误:
ERROR 1452 (23000) at line 5118296: Cannot add or update a child row: a foreign key
constraint fails (`tutotour_tharmobeta1`.`#sql-2039_195b4`, CONSTRAINT
`FK_D367B678BF396750` FOREIGN KEY (`id`) REFERENCES `reponse` (`id`) ON DELETE CASCADE)
在SQL文件中的这一行中,我有:
--
-- Contraintes pour la table `reponse`
--
ALTER TABLE `reponse`
ADD CONSTRAINT `FK_5FB6DEC75DDDBC71` FOREIGN KEY (`error`) REFERENCES
`errorcsv` (`id`),
ADD CONSTRAINT `FK_5FB6DEC78D93D649` FOREIGN KEY (`user`) REFERENCES `user`
(`id`),
ADD CONSTRAINT `FK_5FB6DEC7D6ADE47F` FOREIGN KEY (`epreuve`) REFERENCES
`banque_epreuve_temporaire` (`id`),
ADD CONSTRAINT `FK_5FB6DEC7DCC6487D` FOREIGN KEY (`passage_id`) REFERENCES
`passer_colle` (`id`);
--
-- Contraintes pour la table `reponse_qc`
--
ALTER TABLE `reponse_qc`
ADD CONSTRAINT `FK_D367B678B6F7494E` FOREIGN KEY (`question`) REFERENCES
`qc` (`id`),
ADD CONSTRAINT `FK_D367B678BF396750` FOREIGN KEY (`id`) REFERENCES `reponse`
(`id`) ON DELETE CASCADE;
--
-- Contraintes pour la table `reponse_qr`
--
ALTER TABLE `reponse_qr`
ADD CONSTRAINT `FK_B9D7968A8D5FE0A2` FOREIGN KEY (`idCorrecteur`) REFERENCES
`tuteur` (`id`),
ADD CONSTRAINT `FK_B9D7968ABF396750` FOREIGN KEY (`id`) REFERENCES `reponse`
(`id`) ON DELETE CASCADE,
ADD CONSTRAINT `reponse_qr_ibfk_2` FOREIGN KEY (`idColle`) REFERENCES
`colle_qr` (`id`);
我的实体定义如下:
依据实体:
/**
* Réponse
*
* @ORMTable("reponse")
* @ORMEntity(repositoryClass="PACESColleBundleRepositoryReponseRepository")
* @ORMInheritanceType("JOINED")
* @ORMDiscriminatorColumn(name="discr", type="string")
* @ORMDiscriminatorMap({"reponse"="Reponse", "reponseQC"="ReponseQC",
"reponseQR"="ReponseQR"})
*/
class Reponse
{
/**
* @var integer
*
* @ORMColumn(name="id", type="integer")
* @ORMId
* @ORMGeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORMManyToOne(targetEntity="PACESUserBundleEntityUser", inversedBy="reponses", cascade={"persist"})
* @ORMJoinColumn(name="user", referencedColumnName="id", nullable=true)
*/
private $user;
/**
* @ORMManyToOne(targetEntity="PACESColleBundleEntityErrorCSV", inversedBy="reponses", cascade={"persist"})
* @ORMJoinColumn(name="error", referencedColumnName="id")
*/
private $error;
/**
* @var boolean
* @ORMColumn(name="archive" , type="boolean" , nullable=false, options={"default" = false} )
*/
private $archive;
/**
* @ORMColumn(name="banque", type="boolean", options={"default" = false})
*/
protected $banque;
/**
* @var DateTime
*
* @ORMColumn(name="date", type="datetime", nullable=true)
*/
private $date;
/**
* @ORMManyToOne(targetEntity="PACESColleBundleEntityPasserColle", inversedBy="reponses", cascade={"persist"})
*/
private $passage;
/**
* @ORMManyToOne(targetEntity="PACESBanqueBundleEntityBanqueEpreuveTemporaire", inversedBy="reponses", cascade={"persist"})
* @ORMJoinColumn(name="epreuve", referencedColumnName="id")
*/
private $epreuveTemporaire;
reponseqc:
/**
* ReponseQC
*
* @ORMTable("reponse_qc")
* @ORMEntity(repositoryClass="PACESColleBundleRepositoryReponseQCRepository")
*/
class ReponseQC extends Reponse
{
/**
* @ORMManyToOne(targetEntity="QC", inversedBy="reponses", cascade={"persist"})
* @ORMJoinColumn(name="question", referencedColumnName="id")
*/
private $question;
当我以前导入相同的数据库时,一切都很好,我认为我对结构没有任何更改。
尝试类似于此
的东西$connection = $em->getConnection();
$connection->beginTransaction();
try {
$connection->query('SET FOREIGN_KEY_CHECKS=0');
/* run your query here */
$connection->query('SET FOREIGN_KEY_CHECKS=1');
$connection->commit();
}
catch (Exception $e) {
$connection->rollback();
}
希望这会有所帮助,
Alexandru Cosoi