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

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

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

MySQL Error 1364: When NULL Stops Being an Option

You are seeing error SQLSTATE[HY000]: General error: 1364 Field 'display_name' doesn't have a default value because your database schema has changed under the hood, likely due to how you were interacting with it versus what the underlying storage engine actually allows. The fact that this appeared immediately after moving from MAMP to a native Apache, MySQL, and PHP stack is almost certainly not a change in server capabilities. Native installations of MySQL 5.6.13 behave exactly like the bundled version; they do not suddenly enforce stricter rules on NULL values unless the schema definition itself was altered or if you were inadvertently bypassing constraints in the development environment before.

The core issue here is that your table column for display_name is defined as NOT NULL, but your application logic or previous insertion methods assumed it could be omitted entirely. In many legacy setups or specific IDE configurations, developers might insert rows without explicitly providing a value for every column, relying on the server to default them. However, standard MySQL behavior is strict: if a column is declared NOT NULL and has no DEFAULT constraint, you must provide a value in every INSERT statement. If your application code previously worked around this by using specific placeholders or drivers that automatically stripped empty strings for certain columns, switching environments might have exposed the underlying schema reality where those columns now strictly require data.

To resolve this, you need to inspect the table definition directly. Run the following command against your database to see how display_name is currently configured:

DESCRIBE your_table_name;
-- Or alternatively:
SHOW COLUMNS FROM your_table_name LIKE 'display_name';

If the output shows NULL in the "Null" column, you have a few distinct paths forward depending on whether you want to enforce data integrity or simply fix the immediate insertion error.

Option 1: Allow NULL Values

If display_name is optional within your application's business logic, the most direct fix is to alter the column definition to allow NULL. This restores the previous behavior where omitting the field in an INSERT statement would not cause an error.

ALTER TABLE your_table_name
MODIFY COLUMN display_name VARCHAR(255) NULL;

Note: Replace VARCHAR(255) with whatever data type and length you are currently using. If you don't know the current type, check the output of SHOW COLUMNS first.

Option 2: Add a Default Value

If your application or API contracts require that every row must have a display_name, but users sometimes leave it blank in the UI, you should provide a fallback value. This ensures that even if the input is empty, the database stores a valid string like 'Guest' or an empty string ''.

ALTER TABLE your_table_name
MODIFY COLUMN display_name VARCHAR(255) DEFAULT '';
-- Or for a non-empty fallback:
-- ALTER TABLE your_table_name MODIFY COLUMN display_name VARCHAR(255) DEFAULT 'Guest';

Migration Considerations

A critical detail often missed when altering columns is existing data. If you choose to change NULL behavior, be aware of how it affects current records. If the column currently contains actual data, allowing NULL won't delete that data; however, if the column was previously populated with empty strings '' and you switch to NULL without a default, future inserts will behave differently. Conversely, adding a DEFAULT value only applies to new rows or rows where the column is explicitly set to NULL; it does not retroactively update existing non-null values.

There is a specific nuance with string columns: in some older MySQL configurations or specific driver versions, omitting a string column in an INSERT statement might silently insert an empty string rather than raising an error if the schema wasn't strictly enforced. Moving to a native environment often exposes these latent schema issues because the connection strings and drivers used in MAMP might have had slightly different tolerance settings or the schema was generated dynamically in a way that didn't reflect on-disk constraints until now.

If you are using Laravel, ensure your Eloquent migrations match this reality. You can run:

Schema::table('your_table_name', function (Blueprint $table) {
    $table->string('display_name')->nullable()->change();
});

This confirms the column allows nulls at the database level, preventing runtime errors when you attempt to create users or records without a name. Always verify that your application layer handles the absence of this field gracefully if it becomes optional, as relying solely on the database to accept missing values can lead to inconsistent data states later in the application flow.

Our network