我有一个名为“ FosUser”的实体:
PH
我已经删除了该实体中的字段,并将字段的默认值更改为null('nullable = true'),如下所示:
<?php
namespace techeventBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* FosUser
*
* @ORM\Table(name="fos_user", uniqueConstraints={@ORM\UniqueConstraint(name="UNIQ_957A6479A0D96FBF", columns={"email_canonical"}), @ORM\UniqueConstraint(name="UNIQ_957A647992FC23A8", columns={"username_canonical"}), @ORM\UniqueConstraint(name="UNIQ_957A6479C05FB297", columns={"confirmation_token"})}, indexes={@ORM\Index(name="IDX_957A647914013572", columns={"copon_id"})})
* @ORM\Entity
*/
class FosUser
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="username", type="string", length=180, nullable=true)
*/
private $username;
/**
* @var string
*
* @ORM\Column(name="username_canonical", type="string", length=180, nullable=true)
*/
private $usernameCanonical;
/**
* @var string
*
* @ORM\Column(name="email", type="string", length=180, nullable=false)
*/
private $email;
/**
* @var string
*
* @ORM\Column(name="email_canonical", type="string", length=180, nullable=true)
*/
private $emailCanonical;
/**
* @var boolean
*
* @ORM\Column(name="enabled", type="boolean", nullable=true)
*/
private $enabled;
/**
* @var string
*
* @ORM\Column(name="salt", type="string", length=255, nullable=true)
*/
private $salt;
/**
* @var string
*
* @ORM\Column(name="password", type="string", length=255, nullable=false)
*/
private $password;
/**
* @var \DateTime
*
* @ORM\Column(name="last_login", type="datetime", nullable=true)
*/
private $lastLogin;
/**
* @var string
*
* @ORM\Column(name="confirmation_token", type="string", length=180, nullable=true)
*/
private $confirmationToken;
/**
* @var \DateTime
*
* @ORM\Column(name="password_requested_at", type="datetime", nullable=true)
*/
private $passwordRequestedAt;
/**
* @var array
*
* @ORM\Column(name="roles", type="array", nullable=true)
*/
private $roles;
/**
* @var string
*
* @ORM\Column(name="nom", type="string", length=255, nullable=false)
*/
private $nom;
/**
* @var string
*
* @ORM\Column(name="prenom", type="string", length=255, nullable=false)
*/
private $prenom;
/**
* @var string
*
* @ORM\Column(name="tel", type="string", length=30, nullable=true)
*/
private $tel;
/**
* @var integer
*
* @ORM\Column(name="age", type="integer", nullable=false)
*/
private $age;
/**
* @var string
*
* @ORM\Column(name="sexe", type="string", length=255, nullable=true)
*/
private $sexe;
/**
* @var string
*
* @ORM\Column(name="fonction", type="string", length=255, nullable=true)
*/
private $fonction;
/**
* @var string
*
* @ORM\Column(name="address", type="string", length=255, nullable=true)
*/
private $address;
/**
* @var string
*
* @ORM\Column(name="categorie", type="string", length=255, nullable=true)
*/
private $categorie;
/**
* @var string
*
* @ORM\Column(name="type", type="string", length=255, nullable=true)
*/
private $type;
/**
* @var string
*
* @ORM\Column(name="description", type="string", length=255, nullable=true)
*/
private $description;
/**
* @var string
*
* @ORM\Column(name="role", type="string", length=255, nullable=true)
*/
private $role;
/**
* @var \Coupon
*
* @ORM\ManyToOne(targetEntity="Coupon")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="copon_id", referencedColumnName="id")
* })
*/
private $copon;
}
在更新数据库架构后,我出现了这些错误:
在AbstractMySQLDriver.php第112行中:
执行'ALTER TABLE fos_user CHANGE时发生异常 用户名用户名VARCHAR(180)非空,请更改username_canonical username_canonic al VARCHAR(180)NOT NULL,更改email_canonical email_canonical VARCHAR(18 0)NOT NULL,启用更改启用 TINYINT(1)NOT NULL,更改角色角色LONGTEXT NOT NULL COMMENT '((DC2Type:array)',CHANGE nom nom VARCHAR(255)D EFAULT NULL,更改 prenom prenom VARCHAR(255)DEFAULT NULL':
SQLSTATE [22004]:不允许空值:1138利用率不正确 德拉瓦勒NULL
在PDOConnection.php第106行中:
SQLSTATE [22004]:不允许空值:1138利用率不正确 德拉瓦勒NULL
在PDOConnection.php第104行中:
SQLSTATE [22004]:不允许空值:1138利用率不正确 德拉瓦勒NULL
答案 0 :(得分:0)
您的代码正确! 以前您没有使用过FOUser类,您的fos_user表已经具有用户名,emailCanonical等。 然后,当您扩展FOSUser并更新数据库架构时,当前实体不接受用户名等的空值。(这是FOSUser逻辑)
解决方案,您必须先删除fos_user表,然后再更新数据库架构