zoukankan      html  css  js  c++  java
  • laravel 中 1364 Field 'repost_id' doesn't have a default value

    1.阻止默认响应:preventDefault() 方法阻止元素发生默认的行为(例如,当点击提交按钮时阻止对表单的提交)。http://www.w3school.com.cn/jquery/event_preventdefault.asp

    2.通过js直接到达控制器,而不用通过提交和action : http://api.jquery.com/jQuery.post/

    3.

    错误原因:1. laravel5.5 中链接数据库时,使用模板对数据库进行关联,多对多操作;一般情况下此模板与数据库名相似,根据上图可以看到数据库名为 statuses,所以模板所在位置 appmodelsStatus;(模板为单数)如图所示:。打开文件,找到 $fillable,这里是允许对数据库操作的字段,此处明显没有错误中指出的字段,所以将此处更改为(注意,将这里更改为自己数据表中字段)。

    4.

     错误原因:连续两个创建,造成涌余,所导致错误:(

     Status::create就是参入数据的意思;
    $status->create()也是参入数据的意思;
    但是第一个参入后第二个就没有数据,所以导致这种错误。

    $status = Status::create([
                'repost_id' => (int)$request->report_id,
                'content' => $request->report_text,
                'repost_count'=>1,
                'user_id' =>(int)Auth::user()->id,
            ]);
            $request->repost_count+1;
    //        dd(count($status->repost_count));
    //   $status->create();
    //使用下面这条语句可以在创建新数据时,同时对原数据进行更改:
    use DB;
    DB::table('repost_count') ->where('id', $request->report_id) ->update(['字段名字' => 想给字段赋予的值]);
    
    

      

  • 相关阅读:
    人民币格式化 ,分割
    解决IE下页面空白或者报错:[vuex] vuex requires a Promise polyfill in this browser
    js生成图片
    适用于iview的表格转Excel插件
    js金额转大写数字
    webstorm vue cli 热更新不起作用解决办法
    纯css实现 switch开关
    vue 时间戳转 YYYY-MM-DD h:m:s
    Simple2D-20(重构)
    Simple2D-19(音乐播放器)播放器的源码实现
  • 原文地址:https://www.cnblogs.com/luxia/p/8110515.html
Copyright © 2011-2022 走看看