mysql创建数据库没有默认值报错_mysql,laravel_数据库某个字段没有默认值,mysql,laravel,php - phpStudy...

韦辰钊
2023-12-01

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

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))

相关阅读:

《flask web开发》第四章案例如何运行?

bootstrapDialog弹框垂直居中的办法

python支持固化分组吗?

php用pg_connect()连接pgsql。出现连接数满了,这怎么解决?

列表中的图片做弹出放大,弹出层组件位置放哪里?

Function.prototype是什么?

git fetch --all一直停在Receiving objects

antd upload上传图片到服务器前端怎么配置啊

为什么这段代码访问不了上一级的变量?

大型项目公共样式抽离需要注意的问题?

像今日头条,她社区之类点击刷新数据不重复实现机制是什么?

非laravel使用illuminate/console

python:nupic安装后,执行nupic-master中的程序总会出现系统错误

angular表单未实时显示赋值和进行验证

php 下载 world文件 但是打不开

关于google地图和页面的联动

关于正则表达式在电话号码判断程序中应用的一个问题。

python xlsxwriter画图表时出错?

wx.request res.data输出字符串?

antdesign的Popconfirm气泡确认框怎么阻止冒泡啊

 类似资料: