Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql Table Column Cannot Be Null

Tags:

sql

mysql

I have created a table with three columns, Id , Name , Quantity. It appears that when I am trying to insert a row with at least one null column or when i am trying to set the default value of a column to NULL the database throws an error. #1048 - Column 'Quantity' cannot be null

How can I set NULL as a valid value for a column?

like image 787
jayt.dev Avatar asked Jan 17 '26 05:01

jayt.dev


1 Answers

ALTER TABLE mytable MODIFY quantity NUMERIC(20, 2)

Replace NUMERIC(20, 2) with your actual datatype, but without NOT NULL constraint.

To show your current column definitions, run

SHOW CREATE TABLE mytable

in mysql (the command line client)

like image 58
Quassnoi Avatar answered Jan 19 '26 20:01

Quassnoi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!