我有以下用户实体和fixture文件,但是当我运行app / console doctrine:fixtures:load我得到以下错误并且不确定原因。如果我删除日期字段,灯具生成正常。我在这里错过了什么?感谢。
错误:无法确定如何将created_at分配给AppBundle \ Entity \ User对象
<?php
namespace AppBundle\Entity;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
/**
* User
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="AppBundle\Entity\UserRepository")
*/
class User
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* @var string
*
* @ORM\Column(name="role", type="string", length=255)
*/
private $role;
/**
* @var string
*
* @ORM\Column(name="email", type="string", length=255)
*/
private $email;
/**
* @var string
*
* @ORM\Column(name="phone", type="string", length=16)
*/
private $phone;
/**
* @var \DateTime
*
* @Gedmo\Timestampable(on="create")
* @ORM\Column(name="created_at", type="datetime", nullable=true)
*/
private $createdAt;
/**
* @var \DateTime
*
* @Gedmo\Timestampable(on="update")
* @ORM\Column(name="updated_at", type="datetime", nullable=true)
*/
private $updatedAt;
我的夹具yml:
AppBundle\Entity\User:
user{1..10}:
name: <firstName()> <lastName()>
role: employee
email: <email()>
phone: <numberBetween(1555000000, 1555999999)>
created_at: <datetimeBetween('-5 days', 'now')>
updated_at: <datetimeBetween('-5 days', 'now')>
答案 0 :(得分:1)
不确定,但我认为命名不正确,只是错误说的是什么。我认为应该是:
createdAt: <datetimeBetween('-5 days', 'now')>
updatedAt: <datetimeBetween('-5 days', 'now')>
答案 1 :(得分:0)
我担心您无法手动设置时间戳字段。在documentation和entity example中,此类字段根本没有设置器。因此,在灯具中,您只需删除created_at
和updated_at
(它们将自动设置):
ppBundle\Entity\User:
user{1..10}:
name: <firstName()> <lastName()>
role: employee
email: <email()>
phone: <numberBetween(1555000000, 1555999999)>