为什么我要这个?

错误: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 ;

最佳答案

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

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

10-04 22:25