我正在尝试用dbforge向数据库中添加一个新列,但它只返回错误消息没有进入其他列我的错误:social-settings重复列名' github‘ALTER add github VARCHAR(255)我知道有一个列名github但它没有进入other列,如果列添加失败它会在数据库中插入两个表,我需要从其他表中删除
$last_id=$this->Forms_model->newArea($this->input->post());
if ($last_id!=false) {
$this->load->dbforge();
$fields = array(
$this->input->post("element_name") => array(
'type' => 'VARCHAR',
'constraint' => '255',
),
);
$table = $this->input->post("element_form_id") == 2 ? "contact-settings" : "social-settings";
if ($this->dbforge->add_column($table, $fields)) {
echo json_encode(returnJson(1, "Yeni form alanı ekleme işlemi başarılı."));
} else {
echo $this->Forms_model->turnToOld($last_id) == true ? json_encode(returnJson(0, "Yeni form alanı ekleme işlemi bir sebepten dolayı başarısız oldu.")) : json_encode(returnJson(0, "İşlemler yapılırken bazı hatalar oluştu, lütfen geliştiricinizle iletişime geçin."));
}
}发布于 2019-07-07 00:05:23
表中必须有一个具有该名称的列。
在发出$this->db->field_exists()语句之前,应该使用add_column检查列是否存在。
$el = $this->input->post("element_name");
if (is_null($el)) {
show_error('element is null');
}
if (!$this->db->field_exists($el, 'table_name')) {
// dbforge
}guide/database/metadata.html#determine-if-a-field-is-present-in-a-table
https://stackoverflow.com/questions/56915218
复制相似问题