Php 致命错误:未捕获PDOException:SQLSTATE[23000]:完整性约束冲突:1048列';id';在中不能为空

Php 致命错误:未捕获PDOException:SQLSTATE[23000]:完整性约束冲突:1048列';id';在中不能为空,php,pdo,Php,Pdo,我想问一下。我遇到了一个错误 致命错误:未捕获PDOException:SQLSTATE[23000]:完整性约束冲突:1048列“id”在C:\WTServer\WWW\disc\admin\newsadd.php:79堆栈跟踪:#0 C:\WTServer\WWW\disc\admin\newsadd.php(79):PDOStatement->execute()#1{play}在第79行的C:\WTServer\WWW\disc\admin\newsadd.php中抛出 在数据库中添加外键

我想问一下。我遇到了一个错误

致命错误:未捕获PDOException:SQLSTATE[23000]:完整性约束冲突:1048列“id”在C:\WTServer\WWW\disc\admin\newsadd.php:79堆栈跟踪:#0 C:\WTServer\WWW\disc\admin\newsadd.php(79):PDOStatement->execute()#1{play}在第79行的C:\WTServer\WWW\disc\admin\newsadd.php中抛出

在数据库中添加外键时发生 我不知道我应该怎么做,到目前为止我还没有找到正确的编码

tbl_登录的外键(id)

我的代码newsadd.php

        if(!isset($errMSG))
    {
        $stmt = $db->prepare('INSERT INTO tbl_news(newsid,id, newstitle,newsauthor,newsimg,newscontent) VALUES(:unews, :idlogin, :utitle, :uauthor, :uimg, :ucontent)');
        $stmt->bindParam(':unews',$newsid);
        $stmt->bindParam(':idlogin',$id);
        $stmt->bindParam(':utitle',$newstitle);
        $stmt->bindParam(':uauthor',$newsauthor);

        $stmt->bindParam(':uimg',$newsimg);

        $stmt->bindParam(':ucontent',$newscontent);

        if($stmt->execute())
        {
            $successMSG = "new record succesfully inserted ...";
            header("refresh:5;news.php"); // redirects image view page after 5 seconds.
        }
        else
        {
            $errMSG = "error while inserting....";
        }
    }
}
?>

如果($stmt->execute())第79行出现错误
*对不起,我的英语不好

可能是因为试图在同一个字段中写入数据(对于唯一id字段)

这意味着
$id
$stmt->bindParam(':idlogin',$id')中为空。您应该将其var转储,并确保var设置正确id列未设置为null。但若我设置null id列,数据将保存,但id为null。如何保存?我不明白