I'm using Doctrine2 in my symfony2.8-based website to interact with the database. I created the table successfully using the command line tool (doctrine:schema:create).
But after running the command doctrine:schema:update --dump-sql
and then doctrine:schema:update --force
, I came to find out only the columns "id" and "name" had been created in my MySQL database.
I've checked the mapping data (annotations) on my entity and run the 2 latter commands again, but the table is still the same with the command line tool returning the message saying "Nothing to update - your database is already in sync with the current entity metadata."
Any suggestions or remarks?
Please find below how my entity look like:
<?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;
}
}
最后,我能够通过手动创建我的表来解决这个问题,然后在我现有的数据库中生成我的实体,如下所述: http : //symfony.com/doc/current/cookbook/doctrine/reverse_engineering.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.