数据库某个字段没有默认值

mysql error.

SQLSTATE[HY000]: General error: 1364 Field 'uuid' doesn't have a default value (SQL: insert into `comments` (`markdown`, `updated_at`, `created_at`) values (Hello, 2016-11-24 14:51:13, 2016-11-24 14:51:13))

CommentController

/**
     * Create comment.
     *
     * @param Request $request
     *
     * @return json
     */
    public function commentCreate(CommentCreateRequest $request)
    {
        try {
            $currentUser = JWTAuth::parseToken()->authenticate();
            $input = $request->input();

            $html = Parsedown::instance()->text($input['markdown']);
            $uuid = UUID::uuid1()->toString();
            $status = 'published';

            $input = array_add($input, 'uuid', $uuid);
            $input = array_add($input, 'html', $html);
            $input = array_add($input, 'status', $status);
            $input = array_add($input, 'user_id', $currentUser->id);
            $input = array_add($input, 'created_at', Carbon::now());

            // return $input;
            $comment = $this->comment->create($input);

            return response()->json([
                'code' => 0,
                'data' => $comment,
            ]);
        } catch (ValidationException $e) {
            return response()->json([
                'code' => ErrorCode::FAILED_TO_CREATE_THE_COMMENT,
                'message' => ErrorMessage::FAILED_TO_CREATE_THE_COMMENT,
            ]);
        } catch (QueryException $e) {
            return response()->json([
                'code' => ErrorCode::FAILED_TO_CREATE_THE_COMMENT,
                // 'message' => ErrorMessage::FAILED_TO_CREATE_THE_COMMENT,
                'message' => $e->getMessage(),
            ]);
        }

migration

/**
     * Run the migrations.
     */
    public function up()
    {
        Schema::create('comments', function (Blueprint $table) {
            $table->uuid('uuid');
            $table->increments('id');
            $table->integer('user_id')->unsigned();
            $table->integer('post_id')->unsigned();
            $table->text('markdown');
            $table->text('html');
            $table->string('status');
            $table->timestamps();
            $table->softDeletes();

            $table->engine = 'InnoDB';
        });
    }

补充:

主要是其他表也有 uuid 这个表,比如 Post 表,就没有问题。

我把 uuid 字段删除后,又报下面的错误:

SQLSTATE[HY000]: General error: 1364 Field 'user_id' doesn't have a default value (SQL: insert into `comments` (`markdown`, `updated_at`, `created_at`) values (Hello, 2016-11-24 15:29:11, 2016-11-24 15:29:11))
查看回复