由于Integrity约束违规,Propel无法删除

时间:2015-01-22 14:35:00

标签: mysql foreign-keys constraints propel

我在Propel 1.6.9上运行,之前的开发人员最近更新了文件,因为我在笔记本电脑上生成正确的文件时仍然遇到一些问题。除了在尝试删除某些内容时遇到的一个问题,一切顺利。

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`db000_app/file_meta`, CONSTRAINT `file_meta_FK_1` FOREIGN KEY (`case_id`) REFERENCES `agency_costs` (`id`))' in /var/www/vhosts/10/154462/webspace/httpdocs/domain/vendor/propel/propel1/runtime/lib/connection/DebugPDOStatement.php:90 

Stack trace: 
#0 /var/www/vhosts/10/154462/webspace/httpdocs/domain/vendor/propel/propel1/runtime/lib/connection/DebugPDOStatement.php(90): PDOStatement->execute(NULL) 
#1 /var/www/vhosts/10/154462/webspace/httpdocs/domain/vendor/propel/propel1/runtime/lib/util/BasePeer.php(145): DebugPDOStatement->execute() 
#2 /var/www/vhosts/10/154462/webspace/httpdocs/domain/vendor/propel/propel1/build/classes/onterechtbetaald/om/BaseAgencyCostsPeer.php(1085): BasePeer::doDelete(Object(AgencyCostsQuery), Object(DebugPDO)) 
#3 [internal function]: BaseAgencyCo in /var/www/vhosts/10/154462/webspace/httpdocs/domain/vendor/propel/propel1/runtime/lib/util/BasePeer.php on line 149

调用删除功能的代码:

$case = AgencyCostsQuery::create()->findPk($_POST["DeleteId"]);

if ($case !== null)
{
  $case->deleteFiles();
  $case->delete();
}

如上所述,这在文件更新之前工作得很好。数据库已更改:已向agency_costs添加了两列。

有关如何克服此错误的任何想法?

1 个答案:

答案 0 :(得分:-1)

问题是由数据库中约束的定义引起的。 约束设置为限制删除和更新。 将此更改为级联解决了我的问题。