首页 > 解决方案 > Rest API:#1062 - 键“主”的重复条目

问题描述

这是我的错误 .GIF

我想使用 Codeigniter 将一些图像上传到带有 rest API 的服务器。

但是在这张表上上传图片/刷新 phpmyadmin 后我遇到了问题。

我知道这个问题很经典,我已经在做:

  1. 重新创建表 2 次。
  2. ID设为 Autoincrement(实际上我是在第一次制作表时将其设为 AI)
  3. 插入操作不包括ID,并使其自动进行。
  4. 我已经将表格截断了 2 次

但没有任何改变,在我刷新页面 phpmyadmin 时,这个错误总是出现。

我的错误是什么?

谢谢

如果您认为我的错误是因为我的代码 Rest-API,这是我的代码:

控制器

public function upload_post()
{
    // $config['max_size']  = '100';
    // $config['max_width']  = '1024';
    // $config['max_height']  = '768';

    $msgCreated = ['status' => true, 'message' => 'Image Has Been Upload'];
    $msgFailCreated = ['status' => false, 'message' => 'Failed to Upload Image !'];
    $config['upload_path'] = './image/';
    $config['allowed_types'] = 'gif|jpg|png';

    $this->load->library('upload', $config);
    $this->upload->initialize($config);
    if (!$this->upload->do_upload('file')) {
        $this->set_response($msgFailCreated, 404);
    } else {
        $info = $this->upload->data();
        $image_path = base_url("image/" . $info['raw_name'] . $info['file_ext']);
        $data = [
            "name_image" => $this->input->post('name_image'),
            "image" => $image_path
        ];
        if ($this->mahasiswa->insertImage($data)) {
            $this->set_response($msgCreated, 201);
        } else {
            $this->set_response($msgFailCreated, 400);
        }
    }
}

模型:

//? Membuat Upload Image
    public function insertImage($data){
        return $this->db->insert('image', $data);
    }

标签: restcodeigniterphpmyadmin

解决方案


推荐阅读