【发布时间】:2015-04-12 18:07:53
【问题描述】:
我正在尝试向数据库中插入值,但出现了这样的错误 任何人都可以告诉我为什么这个值为 null :
执行'INSERT INTO person (name, age, Footballteam) VALUES (?, ?, ?)' with params [null, null, null]: SQLSTATE [23000]:违反完整性约束:1048 列“名称” 不能为空
这里是实体文件
class Person
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length=100)
*/
protected $name;
/**
* @ORM\Column(type="integer")
*/
protected $age;
/**
* @ORM\Column(type="string", length=100)
*/
protected $footballteam;
/**
* @return mixed
* */
public function getID(){
return $this->$id;
}
/**
* @param mixed $name
* */
public function setName($name){
$this->$name = $name;
return $this;
}
/**
* @return mixed
* */
public function getName(){
return $this->$name;
}
/**
* @param mixed $age
* */
public function setAge($age){
$this->$age = $age;
return $this;
}
/**
* @return mixed
* */
public function getAge(){
return $this->$age;
}
/**
* @param mixed $setFootballteam
* */
public function setFootballteam($footballteam){
$this->$footballteam = $footballteam;
return $this;
}
/**
* @return mixed
* */
public function getFootballteam(){
return $this->$footballteam;
}
}
这里是控制器文件
public function contactAction()
{
$person = new Person();
$person->setName('xuandao');
$person->setAge(20);
$person->setFootballteam("Manchester");
$em = $this->getDoctrine()->getManager();
$em->persist($person);
$em->flush();
return $this->render('rikidaolxBundle:Page:contact.html.twig');
}
【问题讨论】:
-
更改表定义并将列
not null设置为null -
还没有,所有的值都将是 null ,我的问题是为什么实体类中的值是 NULL 即使在控制器类中添加了值