CakePHP上传插件 - Field' photo_dir'没有默认值

时间:2016-12-06 10:22:03

标签: php cakephp file-upload cakephp-2.4

我正在尝试在新托管中设置一个旧的cakePHP应用程序,突然间我在共享godaddy托管上遇到此错误。它在老托管中工作正常。我已经在CakePHP工作了2年,似乎并不明白为什么会这样。我使用以下上传插件cakephp-upload

Error: SQLSTATE[HY000]: General error: 1364 Field 'photo_dir' doesn't have a default value
SQL Query: INSERT INTO `prayag_cms`.`galleries` (`branch_id`, `name`, `album_id`, `display_photo`, `modified`, `created`) VALUES (0, 'Photo', 1, 'CpLMQ28WYAEOnow.jpg_large.jpg', '2016-12-06 10:17:14', '2016-12-06 10:17:14')

这是我的确认

public $actsAs = array(
            'Containable',
    'Upload.Upload' => array(
        'display_photo' => array(
            'fields' => array(
                'dir' => 'photo_dir'
            ),
                            'thumbnailSizes' => array(
                'small' => '250x250',
            ),
                            'thumbnailMethod' => 'php',
                            'path' => '{ROOT}webroot{DS}img{DS}{model}{DS}',
        ),

    )
);

控制器:

public function admin_add() {
    if ($this->request->is('post')) {
        $this->Gallery->create();
        if ($this->Gallery->save($this->request->data)) {
            $this->Session->setFlash(__('The gallery has been saved.'), 'admin/flash_success');
            return $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash(__('The gallery could not be saved. Please, try again.'), 'admin/flash_error');
        }
    }
    $branches = $this->Gallery->Branch->find('list');
    $albums = $this->Gallery->Album->find('list');
    $this->set(compact('branches', 'albums'));
}

1 个答案:

答案 0 :(得分:1)

可能正在发生文件夹不存在(webroot / img / users [model])或没有足够的权限来创建新文件夹或访问文件夹。

  1. 因此未上传照片
  2. 如果未上传照片,则photo_dir分配为空
  3. 但您的数据库字段不接受NULL值
  4. 然后你得到那些错误
  5. 希望你的问题能够得到解决