提问者:小点点

如何没有数据库错误的productController 42S22


我做了一个应用程序,显示一些产品的价格注册人。创建产品页面时显示数据库错误错误:SQLSTATE[42S22]:找不到列:1054未知列'Product.utype'在'where子句'"

我的productsController是这样的:

class ProductsController extends AppController {


    public function index() {
       $this->Product->recursive = 0;

       $products = $this->Product->find('all');
       $this->set('products', $Product);

    }

    /**
    * view method
    *
    * @throws NotFoundException
    * @param string $id
    * @return void
    */

    public function view($id = null) {
        $this->Product->id = $id;
            if (!$this->Product->exists()) {
                throw new NotFoundException(__('Invalid Product'));
            }
        $this->set('products', $this->Product->read(null, $id));
    }
}

和模型产品。php是这样的:

class Product extends AppModel {
public $primaryKey = 'id_prod';
/**
 * belongsTo associations
 *
 * @var array
 */
    public $belongsTo = array(
        'Occurrence' => array(
            'className' => 'Occurrence',
            'foreignKey' => 'occurrence_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        ),
        'User' => array(
            'className' => 'User',
            'foreignKey' => 'user_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )
    );
}

你能帮帮我吗?非常感谢。


共1个答案

匿名用户

根据非常明确的错误:

错误:SQLSTATE[42S22]:未找到列:1054未知列“产品”。u在where子句中键入'

您的代码正在查找产品表中的colum'utype'(显然不存在)。如果你不确定你的代码在哪里告诉它这样做,只需在项目范围内搜索“utype”,并将其更新为正确的字段名。