Search code examples
phplaravellaravel-5voyager

Laravel Voyager SQLSTATE[HY000]: General error: 1364 Field 'id' doesn't have a default value


I'm using voyager as admin panel in my backend getting this type of error while creating BREAD

SQLSTATE[HY000]: General error: 1364 Field 'id' doesn't have a default value (SQL:
insert into `data_types` (`name`, `display_name_singular`, `display_name_plural`,
`slug`, `icon`, `model_name`, `controller`, `policy_name`, `generate_permissions`,
`details`, `description`, `server_side`, `updated_at`, `created_at`) values (hdept,
Hdept, Hdepts, hdept, , App\Hdept, , , 1, {"order_column":null, "order_display_column":null,
"order_direction":"asc", "default_search_key":null}, , 0, 2019-03-04 12:56:29,
2019-03-04 12:56:29))

model (Hdept.php)

namespace App;

use Illuminate\Database\Eloquent\Model;

class Hdept extends Model
{
    protected $fillables = [ 'id'];
}

for bread refernce


Solution

  • This simply means you need to specify the value for id when you insert a new record or you need to provide a default value in your table definition.

    You could define an auto-incrementing id in your migration:

    $table->increments('id');