查询错误:列不能为空-无效查询

时间:2019-09-07 01:26:30

标签: php codeigniter

我在方法中使用代码php张贴在“ tr_no_hp”列中 像

$nomorhp = $this->input->get('nomor_hp');

但是我尝试在数据库列中插入后不能为null。 如何解决这个问题

这是我的控制器代码

$nomorhp = $this->input->get('nomor_hp');
$data = array(
                    'us_id' => $this->user->us_id,
                    'sv_id' => $voucher->sv_id,
                    'op_id' => $voucher->op_id,
                    'tr_id_plgn' => $nomor,
                    'tr_no_hp' => $nomorhp,


                );

                 $this->db->insert('transaksi', $data);
                 $trx_id =$this->db->insert_id();

我得到了这个错误代码

Query error: Column 'tr_no_hp' cannot be null - Invalid query: INSERT INTO `transaksi`

谢谢

2 个答案:

答案 0 :(得分:0)

您可以修改表以允许为空(但这可能会破坏其他内容)或设置默认值。

例如:

$nomorhp = $this->input->get('nomor_hp') ?: ''; // Default to empty string

答案 1 :(得分:0)

在phpmyadmin中将'tr_no_hp'列的默认值分配给NULL

enter image description here