Stillfinder
4 months ago
718
2
Nova

SQLSTATE[HY000]: Field 'user_id' doesn't have a default value

Posted 4 months ago by Stillfinder

Hello.

I'm trying to create a post from the Nova interface, but getting an error:

SQLSTATE[HY000]: General error: 1364 Field 'user_id' doesn't have a default value (SQL: insert into `posts` (`title`, `excerpt`, `body`, `slug`, `updated_at`, `created_at`) values (asdf, asdf, <div>asdf</div>, asdf-1, 2020-04-04 06:26:10, 2020-04-04 06:26:10)) {"userId":1,"exception":"[object] (Illuminate\Database\QueryException(code: HY000): SQLSTATE[HY000]: General error: 1364 Field 'user_id' doesn't have a default value (SQL: insert into `posts` (`title`, `excerpt`, `body`, `slug`, `updated_at`, `created_at`) values (asdf, asdf, <div>asdf</div>, asdf-1, 2020-04-04 06:26:10, 2020-04-04 06:26:10)) at /Users/svd/code/stillfinder-net/vendor/laravel/framework/src/Illuminate/Database/Connection.php:669)

my Nova/Post.php fields method:

 public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),

            Text::make('Title'),
            Text::make('Excerpt'),
            Trix::make('Body')
        ];
    }

my Posts migration:

public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('slug')->unique();
            $table->string('title');
            $table->text('excerpt');
            $table->text('body');
            $table->unsignedBigInteger('user_id');
            $table->softDeletes();
            $table->timestamps();
        });
    }

Appreciate any help

Please sign in or create an account to participate in this conversation.