title: My filename is not persisted in my database with Vichuploader
body: <p>I tried to upload images in my database with Symfony 5 and Vichuploader bundle but my filename is not persisted in my database and I don't know why.</p>
  <p>This the error that I have : <strong>An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'filename' cannot be null</strong></p>
  <p>This is my entity Person.php :</p>
  <pre><code>
  namespace App\Entity;
  
  use App\Repository\PersonRepository;
  use Doctrine\Common\Collections\ArrayCollection;
  use Doctrine\Common\Collections\Collection;
  use Doctrine\ORM\Mapping as ORM;
  use Symfony\Component\Validator\Constraints as Assert;
  
  /**
   * @ORM\Entity(repositoryClass=PersonRepository::class)
   */
  class Person
  {
      /**
       * @ORM\Id
       * @ORM\GeneratedValue
       * @ORM\Column(type=&quot;integer&quot;)
       */
      private $id;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255)
       */
      private $name;
  
      /**
       * @ORM\Column(type=&quot;datetime&quot;)
       */
      private $birthDate;
  
      /**
       * @ORM\ManyToMany(targetEntity=Movie::class, mappedBy=&quot;writers&quot;)
       */
      public $writedMovies;
  
      /**
       * @ORM\ManyToMany(targetEntity=Movie::class, mappedBy=&quot;directors&quot;)
       */
      private $directedMovies;
  
      /**
       * @ORM\ManyToMany(targetEntity=Movie::class, mappedBy=&quot;producers&quot;)
       */
      private $producedMovies;
  
      /**
       * @ORM\OneToMany(targetEntity=MovieActor::class, mappedBy=&quot;person&quot;, orphanRemoval=true, cascade={&quot;persist&quot;})
       */
      private $movieActors;
  
      /**
       * @ORM\Column(type=&quot;boolean&quot;)
       */
      private $sex;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255, nullable=true)
       */
      private $pseudo;
  
      /**
       * @ORM\Column(type=&quot;datetime&quot;, nullable=true)
       */
      private $deathDate;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255, nullable=true)
       */
      private $firstname;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255, nullable=true)
       */
      private $middleName;
  
      /**
       * @ORM\Column(type=&quot;text&quot;, nullable=true)
       */
      private $biography;
  
      /**
       * @ORM\OneToMany(targetEntity=MovieMusicComposer::class, mappedBy=&quot;person&quot;)
       */
      private $movieMusicComposers;
  
      /**
       * @ORM\OneToMany(targetEntity=AwardPerson::class, mappedBy=&quot;person&quot;)
       */
      private $awardPeople;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255, nullable=true)
       */
      private $award1;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255, nullable=true)
       */
      private $award2;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255, nullable=true)
       */
      private $award3;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255, nullable=true)
       */
      private $award4;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255, nullable=true)
       */
      private $award5;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255, nullable=true)
       */
      private $award6;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=100, nullable=true)
       */
      private $nationality;
  
      /**
       * @ORM\OneToMany(targetEntity=PicturePerson::class, mappedBy=&quot;person&quot;, orphanRemoval=true, cascade={&quot;persist&quot;})
       */
      private $picturePeople;
  
      /**
       * @Assert\All({
       *   @Assert\Image(mimeTypes=&quot;image/jpeg&quot;)
       * })
       */
      private $pictureFiles;
  
      /**
       * @ORM\Column(type=&quot;datetime&quot;)
       */
      private $created_at;
  
      /**
       * @ORM\Column(type=&quot;datetime&quot;)
       */
      private $updated_at;
  
      public function __construct()
      {
          $this-&gt;writedMovies = new ArrayCollection();
          $this-&gt;movieActors = new ArrayCollection();
          $this-&gt;movieMusicComposers = new ArrayCollection();
          $this-&gt;awardPeoples = new ArrayCollection();
          $this-&gt;directedMovies = new ArrayCollection();
          $this-&gt;producedMovies = new ArrayCollection();
          $this-&gt;awardPeople = new ArrayCollection();
          $this-&gt;picturePeople = new ArrayCollection();
          $this-&gt;created_at = new \DateTime();
          $this-&gt;updated_at = new \DateTime();
      }
  
      public function getId(): ?int
      {
          return $this-&gt;id;
      }
  
      public function getName(): ?string
      {
          return $this-&gt;name;
      }
  
      public function setName(string $name): self
      {
          $this-&gt;name = $name;
  
          return $this;
      }
  
      public function getBirthDate(): ?\DateTimeInterface
      {
          return $this-&gt;birthDate;
      }
  
      public function setBirthDate(\DateTimeInterface $birthDate): self
      {
          $this-&gt;birthDate = $birthDate;
  
          return $this;
      }
  
      /**
       * @return Collection|Movie[]
       */
      public function getWritedMovies(): Collection
      {
          return $this-&gt;writedMovies;
      }
  
      public function addWritedMovie(Movie $writedMovie): self
      {
          if (!$this-&gt;writedMovies-&gt;contains($writedMovie)) {
              $this-&gt;writedMovies[] = $writedMovie;
          }
  
          return $this;
      }
  
      public function removeWritedMovie(Movie $writedMovie): self
      {
          $this-&gt;writedMovies-&gt;removeElement($writedMovie);
  
          return $this;
      }
  
  
      /**
       * @return Collection|MovieActor[]
       */
      public function getMovieActors(): Collection
      {
          return $this-&gt;movieActors;
      }
  
      public function addMovieActor(MovieActor $movieActor): self
      {
          if (!$this-&gt;movieActors-&gt;contains($movieActor)) {
              $this-&gt;movieActors[] = $movieActor;
              $movieActor-&gt;setPerson($this);
          }
  
          return $this;
      }
  
      public function removeMovieActor(MovieActor $movieActor): self
      {
          if ($this-&gt;movieActors-&gt;removeElement($movieActor)) {
              // set the owning side to null (unless already changed)
              if ($movieActor-&gt;getPerson() === $this) {
                  $movieActor-&gt;setPerson(null);
              }
          }
  
          return $this;
      }
  
      public function getSex(): ?bool
      {
          return $this-&gt;sex;
      }
  
      public function setSex(bool $sex): self
      {
          $this-&gt;sex = $sex;
  
          return $this;
      }
  
      public function getPseudo(): ?string
      {
          return $this-&gt;pseudo;
      }
  
      public function setPseudo(?string $pseudo): self
      {
          $this-&gt;pseudo = $pseudo;
  
          return $this;
      }
  
      public function getDeathDate(): ?\DateTimeInterface
      {
          return $this-&gt;deathDate;
      }
  
      public function setDeathDate(?\DateTimeInterface $deathDate): self
      {
          $this-&gt;deathDate = $deathDate;
  
          return $this;
      }
  
      public function getFirstname(): ?string
      {
          return $this-&gt;firstname;
      }
  
      public function setFirstname(?string $firstname): self
      {
          $this-&gt;firstname = $firstname;
  
          return $this;
      }
  
      public function getMiddleName(): ?string
      {
          return $this-&gt;middleName;
      }
  
      public function setMiddleName(string $middleName): self
      {
          $this-&gt;middleName = $middleName;
  
          return $this;
      }
  
      public function getBiography(): ?string
      {
          return $this-&gt;biography;
      }
  
      public function setBiography(?string $biography): self
      {
          $this-&gt;biography = $biography;
  
          return $this;
      }
  
      /**
       * @return Collection|MovieMusicComposer[]
       */
      public function getMovieMusicComposers(): Collection
      {
          return $this-&gt;movieMusicComposers;
      }
  
      public function addMovieMusicComposer(MovieMusicComposer $movieMusicComposer): self
      {
          if (!$this-&gt;movieMusicComposers-&gt;contains($movieMusicComposer)) {
              $this-&gt;movieMusicComposers[] = $movieMusicComposer;
              $movieMusicComposer-&gt;setPerson($this);
          }
  
          return $this;
      }
  
      public function removeMovieMusicComposer(MovieMusicComposer $movieMusicComposer): self
      {
          if ($this-&gt;movieMusicComposers-&gt;removeElement($movieMusicComposer)) {
              // set the owning side to null (unless already changed)
              if ($movieMusicComposer-&gt;getPerson() === $this) {
                  $movieMusicComposer-&gt;setPerson(null);
              }
          }
  
          return $this;
      }
  
      /**
       * @return Collection|Movie[]
       */
      public function getDirectedMovies(): Collection
      {
          return $this-&gt;directedMovies;
      }
  
      public function addDirectedMovie(Movie $directedMovie): self
      {
          if (!$this-&gt;directedMovies-&gt;contains($directedMovie)) {
              $this-&gt;directedMovies[] = $directedMovie;
              $directedMovie-&gt;addDirector($this);
          }
  
          return $this;
      }
  
      public function removeDirectedMovie(Movie $directedMovie): self
      {
          if ($this-&gt;directedMovies-&gt;removeElement($directedMovie)) {
              $directedMovie-&gt;removeDirector($this);
          }
  
          return $this;
      }
  
      /**
       * @return Collection|Movie[]
       */
      public function getProducedMovies(): Collection
      {
          return $this-&gt;producedMovies;
      }
  
      public function addProducedMovie(Movie $producedMovie): self
      {
          if (!$this-&gt;producedMovies-&gt;contains($producedMovie)) {
              $this-&gt;producedMovies[] = $producedMovie;
              $producedMovie-&gt;addProducer($this);
          }
  
          return $this;
      }
  
      public function removeProducedMovie(Movie $producedMovie): self
      {
          if ($this-&gt;producedMovies-&gt;removeElement($producedMovie)) {
              $producedMovie-&gt;removeProducer($this);
          }
  
          return $this;
      }
  
      /**
       * @return Collection|AwardPerson[]
       */
      public function getAwardPeople(): Collection
      {
          return $this-&gt;awardPeople;
      }
  
      public function addAwardPerson(AwardPerson $awardPerson): self
      {
          if (!$this-&gt;awardPeople-&gt;contains($awardPerson)) {
              $this-&gt;awardPeople[] = $awardPerson;
              $awardPerson-&gt;setPerson($this);
          }
  
          return $this;
      }
  
      public function removeAwardPerson(AwardPerson $awardPerson): self
      {
          if ($this-&gt;awardPeople-&gt;removeElement($awardPerson)) {
              // set the owning side to null (unless already changed)
              if ($awardPerson-&gt;getPerson() === $this) {
                  $awardPerson-&gt;setPerson(null);
              }
          }
  
          return $this;
      }
  
      public function getAward1(): ?string
      {
          return $this-&gt;award1;
      }
  
      public function setAward1(?string $award1): self
      {
          $this-&gt;award1 = $award1;
  
          return $this;
      }
  
      public function getAward2(): ?string
      {
          return $this-&gt;award2;
      }
  
      public function setAward2(?string $award2): self
      {
          $this-&gt;award2 = $award2;
  
          return $this;
      }
  
      public function getAward3(): ?string
      {
          return $this-&gt;award3;
      }
  
      public function setAward3(?string $award3): self
      {
          $this-&gt;award3 = $award3;
  
          return $this;
      }
  
      public function getAward4(): ?string
      {
          return $this-&gt;award4;
      }
  
      public function setAward4(?string $award4): self
      {
          $this-&gt;award4 = $award4;
  
          return $this;
      }
  
      public function getAward5(): ?string
      {
          return $this-&gt;award5;
      }
  
      public function setAward5(?string $award5): self
      {
          $this-&gt;award5 = $award5;
  
          return $this;
      }
  
      public function getAward6(): ?string
      {
          return $this-&gt;award6;
      }
  
      public function setAward6(?string $award6): self
      {
          $this-&gt;award6 = $award6;
  
          return $this;
      }
  
      public function getNationality(): ?string
      {
          return $this-&gt;nationality;
      }
  
      public function setNationality(?string $nationality): self
      {
          $this-&gt;nationality = $nationality;
  
          return $this;
      }
  
      /**
       * @return Collection|PicturePerson[]
       */
      public function getPicturePeople(): Collection
      {
          return $this-&gt;picturePeople;
      }
  
      public function addPicturePerson(PicturePerson $picturePerson): self
      {
          if (!$this-&gt;picturePeople-&gt;contains($picturePerson)) {
              $this-&gt;picturePeople[] = $picturePerson;
              $picturePerson-&gt;setPerson($this);
          }
  
          return $this;
      }
  
       /**
       * @return mixed
       */
      public function getPictureFiles()
      {
          return $this-&gt;pictureFiles;
      }
  
      /**
       * @param mixed $pictureFiles
       * @return Person
       */
      public function setPictureFiles($pictureFiles): self
      {
          foreach($pictureFiles as $pictureFile) {
              $picture = new PicturePerson();
              $picture-&gt;setImageFile($pictureFile);
              $this-&gt;addPicturePerson($picture);
          }
          $this-&gt;pictureFiles = $pictureFiles;
          return $this;
      }
  
      public function removePicturePerson(PicturePerson $picturePerson): self
      {
          if ($this-&gt;picturePeople-&gt;removeElement($picturePerson)) {
              // set the owning side to null (unless already changed)
              if ($picturePerson-&gt;getPerson() === $this) {
                  $picturePerson-&gt;setPerson(null);
              }
          }
  
          return $this;
      }
  
      public function getCreatedAt(): ?\DateTimeInterface
      {
          return $this-&gt;created_at;
      }
  
      public function setCreatedAt(\DateTimeInterface $created_at): self
      {
          $this-&gt;created_at = $created_at;
  
          return $this;
      }
  
      public function getUpdatedAt(): ?\DateTimeInterface
      {
          return $this-&gt;updated_at;
      }
  
      public function setUpdatedAt(\DateTimeInterface $updated_at): self
      {
          $this-&gt;updated_at = $updated_at;
  
          return $this;
      }
  }
  </code></pre>
  <p>This is my Entity PicturePerson.php :</p>
  <pre><code>
  namespace App\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use Symfony\Component\HttpFoundation\File\File;
  use Symfony\Component\Validator\Constraints as Assert;
  use Vich\UploaderBundle\Mapping\Annotation as Vich;
  
  /**
   * @ORM\Entity(repositoryClass=PicturePersonRepository::class)
   */
  class PicturePerson
  {
      /**
       * @ORM\Id
       * @ORM\GeneratedValue
       * @ORM\Column(type=&quot;integer&quot;)
       */
      private $id;
  
      /**
       * @var File|null
       * @Assert\Image(
       *     mimeTypes=&quot;image/jpeg&quot;
       * )
       * @Vich\UploadableField(mapping=&quot;person_image&quot;, fileNameProperty=&quot;filename&quot;)
       */
      private $imageFile;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255)
       */
      private $filename;
  
      /**
       * @ORM\ManyToOne(targetEntity=Person::class, inversedBy=&quot;picturePeople&quot;)
       * @ORM\JoinColumn(nullable=false)
       */
      private $person;
  
      public function getId(): ?int
      {
          return $this-&gt;id;
      }
  
      public function getFilename(): ?string
      {
          return $this-&gt;filename;
      }
  
      public function setFilename(?string $filename): self
      {
          $this-&gt;filename = $filename;
  
          return $this;
      }
  
      public function getPerson(): ?Person
      {
          return $this-&gt;person;
      }
  
      public function setPerson(?Person $person): self
      {
          $this-&gt;person = $person;
  
          return $this;
      }
  
       /**
       * @return null|File
       */
      public function getImageFile(): ?File
      {
          return $this-&gt;imageFile;
      }
  
      /**
       * @param null|File $imageFile
       * @return self
       */
      public function setImageFile(?File $imageFile): self
      {
          $this-&gt;imageFile = $imageFile;
          return $this;
      }
  }
  </code></pre>
  <p>This is my config file vich_uploader.yaml :</p>
  <pre><code>    db_driver: orm
  
      mappings:
          movie_image:
              uri_prefix: /images/movies
              upload_destination: '%kernel.project_dir%/public/images/movies'
              namer: Vich\UploaderBundle\Naming\UniqidNamer
          movie_video:
              uri_prefix: /videos/movies
              upload_destination: '%kernel.project_dir%/public/videos/movies'
              namer: Vich\UploaderBundle\Naming\UniqidNamer
          movie_audio:
              uri_prefix: /audios/movies
              upload_destination: '%kernel.project_dir%/public/audios/movies'
              namer: Vich\UploaderBundle\Naming\UniqidNamer
          person_image:
              uri_prefix: /images/person_image
              upload_destination: '%kernel.project_dir%/public/images/person_image'
              namer: Vich\UploaderBundle\Naming\UniqidNamer
  </code></pre>
  <p>This is my form PersonType.php:</p>
  <pre><code>
  namespace App\Form;
  
  use App\Entity\Person;
  use Symfony\Component\Form\AbstractType;
  use Symfony\Component\Form\Extension\Core\Type\BirthdayType;
  use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  use Symfony\Component\Form\Extension\Core\Type\FileType;
  use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  use Symfony\Component\Form\Extension\Core\Type\TextType;
  use Symfony\Component\Form\FormBuilderInterface;
  use Symfony\Component\OptionsResolver\OptionsResolver;
  
  class PersonType extends AbstractType
  {
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder
              -&gt;add('pseudo', TextType::class, [
                  &quot;label&quot; =&gt; &quot;Pseudonyme&quot;,
                  &quot;required&quot; =&gt; false
              ])
              -&gt;add('name', TextType::class, [
                  &quot;label&quot; =&gt; &quot;Nom&quot;,
                  &quot;required&quot; =&gt; true
              ])
              -&gt;add('firstname', TextType::class, [
                  &quot;label&quot; =&gt; &quot;Prénom&quot;,
                  &quot;required&quot; =&gt; true
              ])
              -&gt;add('middleName', TextType::class, [
                  &quot;label&quot; =&gt; &quot;2ème Prénom&quot;,
                  &quot;required&quot; =&gt; false
              ])
              -&gt;add('birthDate', BirthdayType::class, [
                  &quot;widget&quot; =&gt; &quot;single_text&quot;,
                  &quot;label&quot; =&gt; &quot;Date de naissance&quot;,
              ])
              -&gt;add('deathDate', BirthdayType::class, [
                  &quot;widget&quot; =&gt; &quot;single_text&quot;,
                  &quot;label&quot; =&gt; &quot;Date de mort&quot;,
                  &quot;required&quot; =&gt; false
              ])
              -&gt;add('sex', ChoiceType::class, [
                  &quot;label&quot; =&gt; &quot;Genre&quot;,
                  'choices'  =&gt; [
                      'Homme' =&gt; true,
                      'Femme' =&gt; false,
                  ],
              ]) 
              -&gt;add('nationality', TextType::class, [
                  'required' =&gt; false,
                  &quot;label&quot; =&gt; &quot;Nationalité&quot;
              ])
              -&gt;add('award1', TextType::class, [
                  'required' =&gt; false,
                  &quot;label&quot; =&gt; &quot;Récompense 1&quot;
              ])
              -&gt;add('award2', TextType::class, [
                  'required' =&gt; false,
                  &quot;label&quot; =&gt; &quot;Récompense 2&quot;
              ])
              -&gt;add('award3', TextType::class, [
                  'required' =&gt; false,
                  &quot;label&quot; =&gt; &quot;Récompense 3&quot;
              ])
              -&gt;add('award4', TextType::class, [
                  'required' =&gt; false,
                  &quot;label&quot; =&gt; &quot;Récompense 4&quot;
              ])
              -&gt;add('award5', TextType::class, [
                  'required' =&gt; false,
                  &quot;label&quot; =&gt; &quot;Récompense 5&quot;
              ])
              -&gt;add('award6', TextType::class, [
                  'required' =&gt; false,
                  &quot;label&quot; =&gt; &quot;Récompense 6&quot;
              ])
              -&gt;add('pictureFiles', FileType::class, [
                  'required' =&gt; false,
                  'multiple' =&gt; true, 
                  'label' =&gt; 'Chargement d\'images (jpeg uniquement) '
              ])
              -&gt;add('biography', TextareaType::class, [
                  'required' =&gt; false,
                  &quot;label&quot; =&gt; &quot;Biographie&quot;,
              ])
              // -&gt;add('awardPeople', TextType::class, [
              //     &quot;label&quot; =&gt; &quot;Prix remporté(s)&quot;
              // ])
          ;
      }
  
      public function configureOptions(OptionsResolver $resolver)
      {
          $resolver-&gt;setDefaults([
              'data_class' =&gt; Person::class,
          ]);
      }
  }
  </code></pre>