2017-04-16 39 views
3

私は問題を抱えて解決策を見つけることができます。私は私でモデル化するためにやりたいSQLSTATE [23000]:整合性制約違反:19 NOT NULL制約に失敗しました:laravel

は形成が、私は、このエラーに

SQLSTATE [23000]得続ける:整合性制約違反:19 NOT NULL制約が失敗しました:drivers.user_id(SQL:ドライバー」に挿入し(黒、T701344C、2011年4月16日、2017-04-16 18:32:04、2017-04-16午前18時32分04秒))

マイコントローラー

ユーザーモデルのユーザ関係で

ドライバモデルの関係における
public function driver() 
{ 
    return $this->belongsTo(Driver::class); 
} 

public function user() 
{ 
    return $this->belongsTo(User::class, 'user_id'); 
} 

ドライバ表

Schema::create('drivers', function (Blueprint $table) { 
     $table->increments('id'); 
     $table->integer('all_time_job')->nullable(); 
     $table->string('vehicle_color')->nullable(); 
     $table->string('plate_number')->nullable(); 
     $table->date('join_date')->nullable(); 

     $table->integer('user_id')->unsigned()->index(); 
     $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); 

     $table->integer('vehicle_id')->unsigned()->index(); 
     $table->foreign('vehicle_id')->references('id')->on('vehicles'); 
     $table->timestamps(); 
    }); 

ユーザー表

Schema::create('users', function (Blueprint $table) { 
     $table->increments('id'); 
     $table->string('first_name'); 
     $table->string('last_name'); 
     $table->string('phone_number')->unique(); 
     $table->string('avatar')->nullable(); 
     $table->string('dob')->nullable(); 
     $table->string('email')->unique(); 
     $table->string('password'); 
     $table->boolean('verified')->default(false); 
     $table->string('token')->nullable(); 
     $table->rememberToken(); 
     $table->timestamps(); 
    }); 

誰か助けてもらえますか?

ユーザーテーブルにユーザーデータを保存しますが、ドライバテーブルにドライバの日付を保存しません。

Iユーザーlaravel 5.4

+0

が、私は賭け列 'user_id'(その主キーである)に設定されたいかなる' auto_increment'がない私たちに、この表 – RiggsFolly

+0

ためのスキーマを表示します。 – Dygnus

+0

私のスキーマをチェックする –

答えて

0

ください'のuser_id'mass assignableを防ぐために、他のあなたドライバモデルクラスの$充填可能な配列であることを確認してください。

protected $fillable = [ ..., 'user_id', ..., ];

このようにソース: Laravel : Integrity constraint violation

関連する問題