Software⏱️ 2 min read📅 2026-06-03

How to Fix error 1364 Error – mysql error 1364 Field doesn't have a default values

MySQL error 1364 Field doesn't have a default value when using triggers to auto-populate fields.

Quick Answer: The issue arises because the trigger is executed before the insert operation, so the field values are not yet set. To resolve this, you can use a BEFORE UPDATE or AFTER INSERT/UPDATE trigger instead.

The error 'Field doesn't have a default value' (Error no. 1364) occurs when MySQL is unable to automatically populate the CREATED_BY field with the current user's ID, which is set up by the trigger.

🚀 How to Resolve This Issue

Method 1: Setting a Default Value

  1. Step 1: Update the CREATE TABLE statement to include a default value for CREATED_BY, like so:
create table try (name varchar(8), CREATED_BY varchar(40) not null default current_user());

Method 2: Dropping and Re-creating the Trigger

  1. Step 1: Drop the existing trigger using the following query:
drop trigger autoPopulateAtInsert ON try;
  • Step 2: Re-create the trigger with a default value for CREATED_BY, like so:
  • create trigger autoPopulateAtInsert BEFORE INSERT on try for each row set new.CREATED_BY=current_user();

    ✨ Wrapping Up

    By applying one of these methods, you should be able to resolve the 'Field doesn't have a default value' error and successfully populate the CREATED_BY field with the current user's ID.

    Did this fix your problem?

    If not, try searching for specific error codes.

    🔍 Search Error Database

    ❓ Frequently Asked Questions