このクエリを実行する PostgreSQL データベースに 3 つのテーブルがあります。
ALTER TABLE waccount ALTER COLUMN balance SET DEFAULT 0;
ALTER TABLE waccount ALTER COLUMN created SET DEFAULT now();
ALTER TABLE waccount ALTER COLUMN modified SET DEFAULT now();
今、INSERT
このコードを使用して Symfony2 コントローラーから実行しようとすると:
$entity = new Account();
$form = $this->createForm(new AccountType(), $entity);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('wba_show', array('id' => $entity->getAccountId())));
}
私はこれを得る:
パラメータ [1, "01234567890121345678", "BankOfAmerica", null, null, null, 6]:
SQLSTATE[23502]: 非 null 違反: 7 エラー: 列 "balance" の null 値が not-null 制約に違反しています。
Symfony や Doctrine がデフォルト値を扱わないのはなぜですか? 私は何か間違ったことをしていますか、それともここで何かを見逃していますか?
アカウント エンティティ
これは私のアカウント エンティティです。
namespace BankBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Account
*
* @ORM\Entity
* @ORM\Table(name="waccount")
*/
class Account {
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*
*/
protected $account_id;
/**
*
* @ORM\Column(type="string", length=20)
*/
protected $account_number;
/**
*
* @ORM\Column(type="string", length=150)
*/
protected $bank_name;
/**
* @ORM\OneToOne(targetEntity="BankBundle\Entity\AccountType")
* @ORM\JoinColumn(name="account_type", referencedColumnName="type_id")
*/
protected $account_type;
/**
*
* @ORM\Column(type="float")
*/
protected $balance;
/**
* @var \DateTime
* @ORM\Column(type="datetime")
*/
protected $created;
/**
* @var \DateTime
* @ORM\Column(type="datetime")
*/
protected $modified;
public function getAccountId() {
return $this->account_id;
}
public function setAccountNumber($account_number) {
$this->account_number = $account_number;
}
public function getAccountNumber() {
return $this->account_number;
}
public function setAccountType($account_type) {
$this->account_type = $account_type;
}
public function setBankName($bank_name) {
$this->bank_name = $bank_name;
}
public function getBankName() {
return $this->bank_name;
}
public function getAccountType() {
return $this->account_type;
}
public function setBalance($balance) {
$this->balance = (float) $balance;
}
public function getBalance() {
return $this->balance;
}
public function setCreated($created) {
$this->created = $created;
}
public function getCreated() {
return $this->created;
}
public function setModified($modified) {
$this->modified = $modified;
}
public function getModified() {
return $this->modified;
}
}
テーブルwaccount
はDB上に存在します