完整性约束违反错误仅在服务器上

时间:2019-01-27 18:02:58

标签: php mysql

我遇到Integrity constraint violation: 1452 Cannot add or update a child row:错误;

我认为这与foreign constraint有关。

但是我的SQL看起来正确。

此外,它仅在非本地服务器上发生。

  1. 本地主机mysql Ver 8.0.12 for osx10.13 on x86_64 (Homebrew)
  2. 服务器mysql Ver 14.14 Distrib 5.7.24, for Linux (x86_64) using EditLine wrapper

我的错误消息如下。

 An exception occurred while executing 'INSERT INTO AcStatus (friendsStr, followersStr, oneFriendsStr, oneFollowersStr, friendsNum, followersNum, oneFriendsNum, oneFollower  
  sNum, createdAt, updatedAt, enabled, ac_st) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' with params ["2828207060,944898932982685696,1306248181,1028832299054325762,1030018  
  242280972288,1030020969190969344,1054737499443118082,1328082421,995233455683260417,1041877822199934976,1065186035569647616,985898196655259648,830752034085183488,9724266408  
  59934720,1082994874062786560,978215033778814977,915330694468984832,1018880555381751815,906489953814581249,1028032641310711808,1025004564422901761,1045576483840786432,10027  
  65007971602432,1089531262568562688,903352143146393600,1047803936457932801,224570452,138706740,995223326250254336,731377603676774400,970899520220311553,2292932660,317830558  
  9,38836238,803424126257885184,1009439059318431745,1056577591996440579", "830752034085183488,978215033778814977,1005728442657144832,1009439059318431745,44785665,10811191070  
  16085505,1056577591996440579", "2828207060,944898932982685696,1306248181,1028832299054325762,1030018242280972288,1030020969190969344,1054737499443118082,1328082421,9952334  
  55683260417,1041877822199934976,1065186035569647616,985898196655259648,972426640859934720,1082994874062786560,915330694468984832,1018880555381751815,906489953814581249,102  
  8032641310711808,1025004564422901761,1045576483840786432,1002765007971602432,1089531262568562688,903352143146393600,1047803936457932801,224570452,138706740,995223326250254  
  336,731377603676774400,970899520220311553,2292932660,3178305589,38836238,803424126257885184", "1005728442657144832,44785665,1081119107016085505", 37, 7, 33, 3, "2019-01-28  
   02:54:48", "2019-01-28 02:54:48", 1, 6]:                                                                                                                                    

  SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`twitmax`.`AcStatus`, CONSTRAINT `FK_F7258AEB7F7907  
  90` FOREIGN KEY (`ac_st`) REFERENCES `twitteraccount` (`id`) ON DELETE CASCADE)  

这些是我的课。

class AcStatus
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;


    /**
    * @ORM\ManyToOne(targetEntity="Acme\UserBundle\Entity\TwitterAccount", inversedBy="stIds")
    * @ORM\JoinColumn(name="ac_st",referencedColumnName = "id",onDelete="CASCADE")
    */

    private $acId;



    class TwitterAccount
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;


    /**
     *
     * @ORM\OneToMany(targetEntity="Acme\UserBundle\Entity\AcStatus",mappedBy="acId")
     *
     */

    private $stIds;

1 个答案:

答案 0 :(得分:2)

AcStatus列具有外键约束FK_F7258AEB7F7907,这会导致违反。

您需要检查“相关表”值。它很可能没有在Foreign Table上插入相关数据。

您可以使用SHOW ENGINE INNODB STATUS

检查错误详细信息