1

I am trying to insert a record with one field as NULL but is return an ERROR:Column 'paid' cannot be null

NOTE: In Database table column paid is of type integer.

CODE

$sql="INSERT INTO `fees_receipt_temp_table`(`id`, `voucher_no`, `std_id`, `full_name`, `payable_fee`,paid) VALUES ('','$voucher_no','$std_id','$name','$payable',NULL)";
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
Sooraj Abbasi
  • 110
  • 16
  • 2
    It isn't the dataype. You need to check if the column 'paid' allows NULL. Share your table schema if possible – Krishnakumar Feb 15 '17 at 09:19
  • 1
    check your database structure. you probably set the column 'paid' to NOT NULL. remove the constraint – Rotimi Feb 15 '17 at 09:19

2 Answers2

3

It's in your database table settings. If the column is set to be "NOT NULL", clear that constraint.

Fallen
  • 4,435
  • 2
  • 26
  • 46
1

The database column is set on NOT NULL. Because of this the column does not accept NULL values.

If you wanna allow NULL as an option, you can alter it to run the following query.

ALTER TABLE fees_receipt_temp_table
ALTER COLUMN paid INT IS NULL
S.Visser
  • 4,645
  • 1
  • 22
  • 43