【发布时间】:2016-05-04 14:38:57
【问题描述】:
我在基于 symfony2.8 的网站中使用 Doctrine2 与数据库进行交互。我使用命令行工具(doctrine:schema:create)成功创建了表。
但是在运行命令doctrine:schema:update --dump-sql 和doctrine:schema:update --force 之后,我发现在我的MySQL 数据库中只创建了“id”和“name”列。
我检查了我的实体上的映射数据(注释)并再次运行后两个命令,但该表仍然与命令行工具相同,返回消息“无需更新 - 您的数据库已经在与当前实体元数据同步。”
有什么建议或意见吗?
请在下面找到我的实体的样子:
<?php
namespace MainBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Contact
*
* @ORM\Table(name="contact")
* @ORM\Entity(repositoryClass="MainBundle\Repository\ContactRepository")
*/
class Contact
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var \DateTime
*
* @ORM\Column(name="date", type="datetime")
*/
private $date;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* @var string
* @ORM\Column(length=100)
* @Assert\Length(max="100")
* @Assert\NotBlank(message="Please enter your email address")
* @Assert\Email(checkMX=true, message="Please check the email you've provided")
* @ORM\Column(name="email", type="string")
*/
private $email;
/**
* @Assert\Regex(pattern="/^\+?[\d]+$/", message="Please check the phone info you've provided")
* @Assert\Length(max="40")
* @Assert\NotBlank(message="Please enter a phone number")
* @ORM\Column(name="phone", length=40)
*/
private $phone;
/**
* @Assert\NotBlank(message="Please enter a message")
*
* @ORM\Column(name="message", type="text")
*/
private $message;
public function __construct()
{
$this->date = new \DateTime();
}
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set date
*
* @param \DateTime $date
*
* @return Contact
*/
public function setDate($date)
{
$this->date = $date;
return $this;
}
/**
* Get date
*
* @return \DateTime
*/
public function getDate()
{
return $this->date;
}
/**
* Set name
*
* @param string $name
*
* @return Contact
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set email
*
* @param string $email
*
* @return Contact
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set phone
*
* @param string $phone
*
* @return Contact
*/
public function setPhone($phone)
{
$this->phone = $phone;
return $this;
}
/**
* Get phone
*
* @return string
*/
public function getPhone()
{
return $this->phone;
}
/**
* Set message
*
* @param string $message
*
* @return Contact
*/
public function setMessage($message)
{
$this->message = $message;
return $this;
}
/**
* Get message
*
* @return string
*/
public function getMessage()
{
return $this->message;
}
}
【问题讨论】:
-
您是否在使用任何一种学说元数据缓存?还可以尝试在电子邮件字段中合并两个单独的
Column注释。 -
完全没有,我没有对 Symphony 框架中嵌入的 Doctrine lib 进行任何更改。我会尝试合并它,但为什么没有在数据库中创建“电话”和“消息”列?
-
尝试通过删除 cache/* 文件夹手动清除缓存。
-
我刚刚又试了一次,但仍然收到相同的消息:“无需更新 - 您的数据库已与当前实体元数据同步。”
-
确保检查正确的数据库。
标签: php mysql symfony doctrine-orm