Home » Php » php – MySql Error: 1364 Field 'display_name' doesn't have default value

php – MySql Error: 1364 Field 'display_name' doesn't have default value

Posted by: admin April 23, 2020 Leave a comment


I have just switched from a MAMP installation to a native Apache, MySql and PHP installation. I have got everything working, but I have started using my web app in the new environment and suddenly any INSERT commands are resulting in the following error:

SQLSTATE[HY000]: General error: 1364 Field ‘display_name’ doesn’t have a default value

It seems the I am unable to leave a field blank now where I was able to before. I am using MySql version 5.6.13

Is there a way to change this setting in MySql?

How to&Answers:

MySQL is most likely in STRICT mode.

Try running SET GLOBAL sql_mode='' or edit your my.cnf to make sure you aren’t setting STRICT_ALL_TABLES or the like.


MySQL is most likely in STRICT mode, which isn’t necessarily a bad thing, as you’ll identify bugs/issues early and not just blindly think everything is working as you intended.

Change the column to allow null:

ALTER TABLE `x` CHANGE `display_name` `display_name` TEXT NULL

or, give it a default value as empty string:

ALTER TABLE `x` CHANGE `display_name` `display_name` TEXT NOT NULL DEFAULT ''


All of these answers are a good way, but I don’t think you want to always go to your DB and modify the default value that you have set to NULL.

I suggest you go to the app/User.php and modify the protected $fillable so it will take your new fields in the data array used to register.

Let’s say you add a new input field called "first_name", your $fillable should be something like this :

protected $fillable = [ 'first_name', 'email', 'password',]; 

This did it for me. Good luck!


I also faced that problem and there are two ways to solve this in laravel.

  1. first one is you can set the default value as null. I will show you an example:

    public function up()
        Schema::create('users', function (Blueprint $table) {

as the above example, you can set nullable() for that feature. then when you are inserting data MySQL set the default value as null.

  1. second one is in your model set your input field in protected $fillable field. as example:

    protected $fillable = [
        'name', 'email', 'password', 'slug', 'gender','pic'

I think the second one is fine than the first one and also you can set nullable feature as well as fillable in the same time without a problem.


Also, I had this issue using Laravel, but fixed by changing my database schema to allow “null” inputs on a table where I plan to collect the information from separate forms:

public function up()

    Schema::create('trip_table', function (Blueprint $table) {


The ->nullable(); Added to the end. This is using Laravel. Hope this helps someone, thanks!


I got this error when I forgot to add new form fields/database columns to the $fillable array in the Laravel model – the model was stripping them out.