Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rameezisrar's avatar

Unable to add a new field in users Auth Controller

User.php

protected $fillable = [
        'name',
        'email',
        'username'
    ];

Under APp/Http/Auth/RegisterController

return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'username' => "some dynamic value",
            'password' => Hash::make($data['password']),
        ]);

Well whenever I try to register I get this error

eneral error: 1364 Field 'usernmae' doesn't have a default value (SQL: insert into `users` (`name`, `email`, `password`, `last_read_announcements_at`, `trial_ends_at`, `updated_at`, `created_at`) values (test1, [email protected], yLARACASTS_SNIPPET_PLACEHOLDERzI4IjVfXtUljVBMffwyU.CFNuJJ.GfkVQpVQGhglCa8FvsDmcP2e, 2018-05-29 06:15:48, 2018-05-29 06:15:48, 2018-05-29 06:15:48, 2018-05-29 06:15:48)) {"exception":"[object] (Illuminate\Database\QueryException(code: HY000): SQLSTATE[HY000]: General error: 1364 Field 'username' doesn't have a default value (SQL: insert into `users` (`name`, `email`, `password`, `last_read_announcements_at`, `trial_ends_at`, `updated_at`, `created_at`) values (test1, [email protected], yLARACASTS_SNIPPET_PLACEHOLDERzI4IjVfXtUljVBMffwyU.CFNuJJ.GfkVQpVQGhglCa8FvsDmcP2e, 2018-05-29 06:15:48, 2018-05-29 06:15:48, 2018-05-29 06:15:48, 2018-05-29 06:15:48)) at /home/rameez/jedi15/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664, PDOException(code: HY000): SQLSTATE[HY000]: General error: 1364 Field 'usernama' doesn't have a default value at /home/rameez/jedi15/vendor/laravel/framework/src/Illuminate/Database/Connection.php:458)

i have tried assigning a default value in the database as Null but then it always store the NUll value on every register.

I have done that with Laravel a few times but i am unable to do that with Spark. @Cronix

0 likes
3 replies
Thyrosis's avatar

'username' => "some dynamic value",

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

Double check whether your dynamic value is parsed through properly. Doesn't look like it.

Also, this might just be a typo, but the first error reads

1364 Field 'usernmae' doesn't have a default value

Username is spelt incorrectly there.

1 like
Snapey's avatar

Agreed. Looks like a typo error in your migration

1 like

Please or to participate in this conversation.