第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

SQLSTATE [HY000]:常規(guī)錯誤:1364字段“ author_id”沒有默認(rèn)值

SQLSTATE [HY000]:常規(guī)錯誤:1364字段“ author_id”沒有默認(rèn)值

PHP
慕哥6287543 2021-04-26 14:58:23
我實(shí)際上是Laravel Framework的新手。一直試圖發(fā)布到Mysql數(shù)據(jù)庫,我的Author_id出現(xiàn)錯誤。SQLSTATE [HY000]:常規(guī)錯誤:1364字段'author_id'沒有默認(rèn)值。到處都檢查過,但所有努力都證明是失敗的這是遷移public function up(){    Schema::create('posts', function (Blueprint $table) {        //$table->engine = “InnoDB”;        $table->increments('id');        $table->integer('author_id')->unsigned();        $table->foreign('author_id')->unique()->references('id')->on('users')->onDelete('restrict');        $table->string('title');        $table->string('slug')->unique();        $table->text('excerpt');        $table->text('body');        $table->unsignedInteger('user_id');        $table->string('image')->nullable();           $table->timestamps();    });}這是我的create.blade.php: <section class="content">        <div class="row">          <div class="col-xs-12">            <div class="box">              <div class="box-body">              {!! Form::model($post, [                    'method' => 'POST',                    'url'  => 'backend/blog'              ]) !!}               {{-- <form method="POST" action="{{ url('blog/store') }}" enctype="multipart/form-data">                @csrf  --}}                    <div class="form-group {{ $errors->has('title') ? 'has-error' : '' }}">                        {!! Form::label('title') !!}                        {!! Form::text('title', null, ['class' => 'form-control']) !!}                        @if($errors->has('title'))                        <span class="help-block">{{ $errors->first('title') }} </span>                        @endif                    </div>                    <div class="form-group {{ $errors->has('slug') ? 'has-error' : '' }}">                      {!! Form::label('slug') !!}                      {!! Form::text('slug', null, ['class' => 'form-control'])!!}       
查看完整描述

1 回答

?
HUX布斯

TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超6個贊

例如,將Post與當(dāng)前用戶相關(guān)聯(lián)(例如,在將Post保存到db的控制器方法內(nèi)部)可以像以下操作:


// controller method

public function savePost( Request $request )

{

    $data = $request->validate([

        // your validation rules here..

        ]);

    $post = new Post(); // from Post model

    $post->fill($data);

    $post->author()->associate(\Auth::user()); // relate post to current user

    $post->save(); // save to db

    return view('whatever_your_view_is', []);

}

如果您需要更多信息,請發(fā)表評論


在Post模型中進(jìn)行以下更改:


public function author()

{

    return $this->belongsTo(User::Class, 'author_id'); // specify the column which stores the author in posts table

}


查看完整回答
反對 回復(fù) 2021-05-07
  • 1 回答
  • 0 關(guān)注
  • 309 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號