Php 透视表未附加laravel关系
这是我的密码:Php 透视表未附加laravel关系,php,laravel,eloquent,Php,Laravel,Eloquent,这是我的密码: Project::find($project)->users()->attach($user)// $project = '1', $user = '2' 错误是: SQLSTATE[HY000]: General error: 1364 Field 'user_id' doesn't have a default value (SQL: insert into `project_user` (`project_id`) values (2)) 如果你需要迁移 S
Project::find($project)->users()->attach($user)// $project = '1', $user = '2'
错误是:
SQLSTATE[HY000]: General error: 1364 Field 'user_id' doesn't have a default value (SQL: insert into `project_user` (`project_id`) values (2))
如果你需要迁移
Schema::create('project_user', function(Blueprint $table)
{
$table->increments('id');
$table->bigInteger('project_id')->unsigned();
$table->bigInteger('user_id')->unsigned();
可能是什么问题?看起来您的关系签名有错误,请确保如下所示:
//在项目模型中
公共功能用户()
{
返回$this->belongtomany('App\User','project\u User','project\u id','User\u id');
}
plase显示关系。是的,我有属于其他项目的项目,谢谢!