数据库中的表与实体架构不一致

时间:2016-05-04 14:38:57

标签: php mysql symfony doctrine-orm

我在基于symfony2.8的网站中使用Doctrine2与数据库进行交互。我使用命令行工具(doctrine:schema:create)成功创建了表。

但是在运行命令doctrine:schema:update --dump-sql然后doctrine:schema:update --force之后,我发现只在我的MySQL数据库中创建了列“id”和“name”。

我已经检查了我的实体上的映射数据(注释)并再次运行了2个后面的命令,但该表仍与命令行工具相同,返回消息“无需更新 - 您的数据库已在与当前实体元数据同步。“

有任何建议或评论吗?

请在下面找到我的实体的样子:

<?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;
    }
}

0 个答案:

没有答案