if(!$workflow_entity=$em->getRepository('AlbatrossAceBundle:Workflow')->findByIdAndStatus($line[$titleArr['WorkflowStepID']],$line[$titleArr['WorkflowStatus']])){$workflow_entity=newWorkflow();$workflow_entity->setWorkflowStatus($line[$titleArr['WorkflowStatus']]);$workflow_entity->setWorkflowStepID($line[$titleArr['WorkflowStepID']]);$em->persist($workflow_entity);}我只檢查當前數(shù)據(jù)庫中是否已經(jīng)有相同的數(shù)據(jù),但正在插入的數(shù)據(jù)中已經(jīng)有數(shù)個是一樣的數(shù)據(jù).所以插入操作時,給出了這樣的信息Anexceptionoccurredwhileexecuting'INSERTINTOworkflow(workflow_step_id,workflow_status)VALUES(?,?)'withparams["10","Assigned"]:SQLSTATE[23000]:Integrityconstraintviolation:1062Duplicateentry'10-Assigned'forkey'stepid_status_uniq'uniqueConstraints:stepid_status_uniq:columns:[workflow_step_id,workflow_status]我已經(jīng)在數(shù)據(jù)庫中創(chuàng)建唯一約束(我不知道這樣說對不對)但現(xiàn)在正要插入的數(shù)個數(shù)據(jù)在flash之前就存在同樣的數(shù)據(jù)我如何在保存到數(shù)據(jù)庫之前就知道當前數(shù)據(jù)已經(jīng)違反唯一規(guī)則了呢?
Unique Constraint 在保存前如何判斷已經(jīng)有同樣數(shù)據(jù)?
瀟瀟雨雨
2019-04-08 11:18:03