无法创建带日期的固定装置
Can't create fixtures with dates
我有以下用户实体和夹具文件,但是当我 运行 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')>
恐怕您无法手动设置时间戳字段。在 documentation and entity example 中,此类字段根本没有设置器。所以在固定装置中你可以简单地删除 created_at
和 updated_at
(它们将自动设置):
ppBundle\Entity\User:
user{1..10}:
name: <firstName()> <lastName()>
role: employee
email: <email()>
phone: <numberBetween(1555000000, 1555999999)>
不确定,但我认为命名不正确,只是错误的意思。我觉得应该是:
createdAt: <datetimeBetween('-5 days', 'now')>
updatedAt: <datetimeBetween('-5 days', 'now')>
我有以下用户实体和夹具文件,但是当我 运行 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')>
恐怕您无法手动设置时间戳字段。在 documentation and entity example 中,此类字段根本没有设置器。所以在固定装置中你可以简单地删除 created_at
和 updated_at
(它们将自动设置):
ppBundle\Entity\User:
user{1..10}:
name: <firstName()> <lastName()>
role: employee
email: <email()>
phone: <numberBetween(1555000000, 1555999999)>
不确定,但我认为命名不正确,只是错误的意思。我觉得应该是:
createdAt: <datetimeBetween('-5 days', 'now')>
updatedAt: <datetimeBetween('-5 days', 'now')>