完整性约束违反外键约束失败

时间:2016-09-03 03:40:10

标签: foreign-keys laravel-5.2

  

错误 - SQLSTATE [23000]:完整性约束违规:1452无法添加或更新子行:外键约束失败(`assign_project`,CONSTRAINT`assign_project_ibfk_2` FOREIGN KEY(`assigned_to`)REFERENCES`user`(` user_id`))(SQL:插入`assign_project`(`project_id`,`description`,`work_start_date`,`work_end_date`,`assign_status`,`assigned_by`,`assigned_to`)值(1,xyz,2016-09 -02,2016-11-02,1,1,))

用户模型

<?php
 namespace App;
 use Illuminate\Database\Eloquent\Model;

 class User extends Model
 {

  protected $fillable = ["user_id","company_id","first_name","last_name","email","password","confirm_password","phone_number","address","pincode","role_id","user_status"]; 

 }
?>
控制器中的

public function getassignprojectemployee(Request $Request){

  $data = Request::all();
    $input = DB::table('usi_assign_project')
    ->insert($data);

    if($input > 0){
        return Redirect::to('admin_assign_projects_employee');
    }
    else
    {
        return Redirect::to('admin_assign_project');
    }
 }

1 个答案:

答案 0 :(得分:0)

删除模型上的外部关系并重试。