【问题标题】:Error: Integrity constraint violation: 1052 Column错误:违反完整性约束:1052 列
【发布时间】:2012-12-26 05:30:33
【问题描述】:

为什么我会得到这个?

错误:SQLSTATE[23000]:违反完整性约束:1052 字段列表中的“收藏夹”列不明确

SQL Query: UPDATE `twitter`.`tractions` AS `Traction` LEFT JOIN `twitter`.`profiles` AS `Profile` ON (`Traction`.`profile_id` = `Profile`.`id`) SET `Traction`.`favorites` = `favorites` + 1, `Traction`.`errors` = `errors` + 0 WHERE `Traction`.`profile_id` = 4 AND `Traction`.`date` = '2013-01-11'

CakePHP 代码:

$this->Traction->updateAll(array(
                "Traction.favorites"=>"`favorites` + $favorites",
                "Traction.errors"=>"`errors` + $errors"
                ), array(
                'Traction.profile_id'=>$profile['Profile']['id'],
                'Traction.date'=>date('Y-m-d')
            ));

-- 表tractions的表结构

CREATE TABLE IF NOT EXISTS `tractions` (
  `id` int(10) NOT NULL auto_increment,
  `date` date default NULL,
  `profile_id` int(10) default NULL,
  `followings` int(10) default '0',
  `unfollowings` int(10) default '0',
  `favorites` int(10) default '0',
  `retweets` int(10) default '0',
  `thanks` int(10) default '0',
  `errors` int(10) default '0',
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

【问题讨论】:

    标签: mysql sql cakephp-2.1


    【解决方案1】:

    显然这两个表都包含列favorites,也可能包含列errors

    当您加入第二个表时,您可能需要设置Traction.favorites = Profile.favorites + $favoritesTraction.errors = Profile.errors + $errors

    正如 JW 所说。您需要使用完整的标识符

    【讨论】:

      【解决方案2】:

      你需要指定tableName,因为多个表包含相同的列名,

      "Traction.favorites"=>"Traction.`favorites` + $favorites"
      

      【讨论】:

        猜你喜欢
        • 2021-12-13
        • 2015-06-20
        • 1970-01-01
        • 2020-06-14
        • 1970-01-01
        • 2019-10-20
        • 1970-01-01
        • 2020-01-14
        相关资源
        最近更新 更多