Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert into database with setting the default values in phpmyadmin

I have two phpmyadmin both are version 4.2.7 and PHP version is PHP Version 5.4.24 one of phpmyadmin is allowing null values and another not accepting the null values

Phpmyadmin - 1

INSERT INTO table_name (column1,column2,column3,...)
VALUES (value1,value2,value3,...);

Phpmyadmin - 2

In the second table, I didn't give the values for column3 its error like

I got the error:

General error: 1364 Field 'column3' doesn't have a default value.

Even though i didn't set the null for phpmyadmin-1 but its working fine. How can I solve this ? Any suggestion ?

INSERT INTO table_name (column1,column2,...)
VALUES (value1,value2,...);

1 Answers

Check your code is like this

when you create the database you should apply this option as well.image marked in red

And in your code assign Your value3=NULL.

Then add the above function as same.

INSERT INTO table_name (column1,column2,column3,...)
    VALUES (value1,value2,value3,...);

Using MySQL commands (Update 2023/07/20)

With Default value

ALTER TABLE table_name 
MODIFY column3 datatype DEFAULT default_value;

With allowing nullable

ALTER TABLE table_name
MODIFY column3 datatype NULL;
like image 136
Abdulla Nilam Avatar answered Dec 15 '25 10:12

Abdulla Nilam