symfony2.8ベースのWebサイトで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;
}
}
doctrineメタデータキャッシュを使用していますか?また、電子メールフィールドに2つの別々の 'Column'アノテーションをマージしようとします。 –
Symphonyフレームワークに埋め込まれたDoctrine libの内容を変更していません。私はそれをマージしようとしますが、なぜ "電話"と "メッセージ"の列がデータベースに作成されていないのですか? –
cache/*フォルダーを削除して手動でキャッシュをクリアしてください。 –