我想在我的网站中设置一个初始AdminUser。当我将它加载到数据库时,由于“updateAt”字段而无法上载。我收到以下错误,当我离开setUpdatedAt空白:Symfony DataFixtures设置默认值
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'updatedAt' ca
nnot be null
我在夹具文件失败设置的任何值,我得到以下错误:(我曾经尝试输入在这个例子中,实际为准)
[Symfony\Component\Debug\Exception\FatalErrorException]
Parse Error: syntax error, unexpected '"2014-12-26 21:01:40"' (T_CONSTANT_E
NCAPSED_STRING), expecting identifier (T_STRING)
这里是数据文件灯具:
<?php
namespace Usuarios\AdminBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Usuarios\UsersBundle\Entity\User;
class LoadUserData implements FixtureInterface
{
/**
* {@inheritDoc}
*/
public function load(ObjectManager $manager)
{
$userAdmin = new User();
$userAdmin->setUsername('Admin');
$userAdmin->setPlainPassword('1234');
$userAdmin->setEmail('[email protected]');
$userAdmin->setRoles(array('ROLE_ADMIN'));
$userAdmin->setEnabled('1');
$userAdmin->setUpdatedAt(\"2014-12-26 21:01:40");
$manager->persist($userAdmin);
$manager->flush();
}
}
我试过很多不同类型INPUD在updatedAt数据,但我不能得到正确的数据类型或让代码留空。
这里是UpdatedAt实体代码:
<?php
namespace Usuarios\UsersBundle\Entity;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* User
*
* @ORM\Table(name="0_00_users")
* @ORM\Entity
*/
class User extends BaseUser
/**
* @var datetime $updatedAt
*
* @Gedmo\Timestampable(on="update")
* @ORM\Column(name="updatedAt", type="datetime", nullable=true)
*/
protected $updatedAt;
/**
* Set updatedAt
*
* @param \DateTime $updatedAt
* @return User
*/
public function setUpdatedAt($updatedAt)
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* Get updatedAt
*
* @return \DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
我怎样才能解决这个问题呢?
谢谢!我错过了'新'标签。 – Garces