我收到的错误在这里...
使用参数 [null, "2015-08-13 04: 52:18”、“wei23849@aldkfj.com”、“瑞克”、“梅森”、“200”]:
SQLSTATE [23000]:违反完整性约束:1048 列 'image_name' 不能为空
这是实体..
<?php
namespace AppBundle\Entity;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity
* @ORM\Table(name="users")
* @UniqueEntity("email", message="That email is already in use")
* @Vich\Uploadable
*/
class User
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @Vich\UploadableField(mapping="profile_image", fileNameProperty="imageName")
* @var File
*/
private $imageFile;
/**
* @ORM\Column(type="string", length=255)
*
* @var string
*/
private $imageName;
/**
* @ORM\Column(type="datetime")
*
* @var \DateTime
*/
private $updatedAt;
/**
* @Assert\NotBlank()
* @Assert\Email(message="Must be a valid email.")
* @ORM\Column(type="string", length=50)
*/
private $email;
/**
* @Assert\NotBlank()
* @Assert\Regex("/^[a-zA-Z -']+$/")
* @ORM\Column(type="string", length=50)
*/
private $first_name;
/**
* @Assert\NotBlank()
* @Assert\Regex(pattern = "/^[a-zA-Z -']+$/", message="Name must be only letters.")
* @ORM\Column(type="string", length=50, unique=true)
*/
private $last_name;
/**
* @Assert\NotBlank()
* @Assert\Type(type="numeric")
* @Assert\GreaterThan(value=70)
* @ORM\Column(type="decimal")
*/
public $start_weight;
/**
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
*/
public function setImageFile(File $image = null) {
$this->imageFile = $image;
if ($image) {
$this->updatedAt = new \DateTime('now');
}
}
/**
* @return File
*/
public function getImageFile() {
return $this->imageFile;
}
/**
* @param string $imageName
*/
public function setImageName($imageName) {
$this->imageName = $imageName;
}
/**
* @return string
*/
public function getImageName(){
return $this->imageName;
}
public function getEmail()
{
return $this->email;
}
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set first_name
*
* @param string $firstName
* @return User
*/
public function setFirstName($firstName)
{
$this->first_name = $firstName;
return $this;
}
/**
* Get first_name
*
* @return string
*/
public function getFirstName()
{
return $this->first_name;
}
/**
* Set last_name
*
* @param string $lastName
* @return User
*/
public function setLastName($lastName)
{
$this->last_name = $lastName;
return $this;
}
/**
* Get last_name
*
* @return string
*/
public function getLastName()
{
return $this->last_name;
}
/**
* Set start_weight
*
* @param string $startWeight
* @return User
*/
public function setStartWeight($startWeight)
{
$this->start_weight = $startWeight;
return $this;
}
/**
* Get start_weight
*
* @return string
*/
public function getStartWeight()
{
return $this->start_weight;
}
public function __toString() {
return $this->start_weight;
}
}
这是表单类型
<?php
namespace AppBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
/**
*
*/
class UserType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('email', 'email', array('label' => "Your Email",
'attr' => array(
'placeholder' => 'Enter Email',
'class' => 'form-control')))
->add('first_name', 'text', array('label'=>'First Name',
'attr' => array(
'placeholder' => "Enter First Name",
'class' => 'form-control')))
->add('last_name', 'text', array('label'=>'Last Name',
'attr'=> array(
'placeholder' => "Your Last Name",
'class' => 'form-control')))
->add('start_weight', 'text', array('label' => "Your Current Weight",
'attr' => array(
'class' => "form-control",
'placeholder' => "Enter Weight")))
->add('imageFile', 'file')
->add('submit', 'submit', array('label' => "Sign Up!",
'attr' => array(
'class' => 'btn btn-md btn-primary')));
}
public function getName() {
return 'user';
}
}
有趣的是我有两个独立的项目。他们两个在代码方面都是完全相同的。该代码在一个项目中有效,而在另一个项目中无效。我在操作中有转储程序并在 _FILES 上运行它并得到错误代码 0,所以那里没有错。上传实际上正在发生。在内核中,我在两个实例中都有 umask(0000) 所以我知道我没有权限问题。
我找不到任何关于为什么会发生这种情况的信息。