rest - Rest API:#1062 - 键“主”的重复条目
问题描述
我想使用 Codeigniter 将一些图像上传到带有 rest API 的服务器。
但是在这张表上上传图片/刷新 phpmyadmin 后我遇到了问题。
我知道这个问题很经典,我已经在做:
- 重新创建表 2 次。
- 将ID设为 Autoincrement(实际上我是在第一次制作表时将其设为 AI)
- 插入操作不包括ID,并使其自动进行。
- 我已经将表格截断了 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);
}
解决方案
推荐阅读
- c - ***检测到堆栈粉碎***:已终止。任何解决方案?
- kubernetes - Istio:在不同节点注入的 pod 副本无法与 istio 通信
- java - Maven 资源插件不过滤文件
- python - 将不同的数据框合并在一起,但索引可能并不总是相同
- optimization - 划分第一阶段可行性集
- amazon-web-services - 用于循环的 Terraform 嵌套
- python - 如何将带有小时整数的列转换为 datetime pandas 索引?
- jquery - 在 JQuery 对话框文本框中输入单击不会触发 __doPostBack
- sql - 替换重复出现的单词及其前面的字符
- javascript - 如何在javascript中检测2个重叠的div并切换类