title: Symfony forms - Expected argument of type , "string" given at property path
body: <p>I get this error message:
  Expected argument of type "App\Entity\Artist or null", "string" given at property path "artist".</p>
  
  <p>This is the code of my form in symfony</p>
  
  <pre><code>$builder
          -&gt;add('date', DateType::class, [
              'widget' =&gt; 'single_text'
          ])
          -&gt;add('artist', TextType::class)
          -&gt;add('City',TextType::class)
          ;
  </code></pre>
  
  <p>And this is the template:</p>
  
  <pre><code>{{ form_start(form)}}
      {{ form_widget(form)}}
          &lt;button class="btn btn-secondary"&gt;{{ button|default('Enregistrer')}}&lt;/button&gt;
  {{ form_end(form)}}
  </code></pre>
  
  <p>Entity</p>
  
  <pre><code>class Artist
  {
  /**
   * @ORM\Id()
   * @ORM\GeneratedValue()
   * @ORM\Column(type="integer")
   */
  private $id;
  /**
   * @ORM\Column(type="string", length=45)
   */
  private $name;
  /**
   * @ORM\OneToMany(targetEntity="App\Entity\Event", mappedBy="artist", cascade={"persist","remove"})
   */
  private $events;
  public function __construct()
  {
      $this-&gt;events = new ArrayCollection();
  }
  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;
  }
  /**
   * @return Collection|Event[]
   */
  public function getEvents(): Collection
  {
      return $this-&gt;events;
  }
  public function addEvent(Event $event): self
  {
      if (!$this-&gt;events-&gt;contains($event)) {
          $this-&gt;events[] = $event;
          $event-&gt;setArtist($this);
      }
      return $this;
  }
  public function removeEvent(Event $event): self
  {
      if ($this-&gt;events-&gt;contains($event)) {
          $this-&gt;events-&gt;removeElement($event);
          // set the owning side to null (unless already changed)
          if ($event-&gt;getArtist() === $this) {
              $event-&gt;setArtist(null);
          }
      }
      return $this;
  }
  public function __toString()
  {
      return $this-&gt;name;
  }
  }
  </code></pre>
  
  <p>This is the error :</p>
  
  <pre><code>Uncaught PHP Exception Symfony\Component\PropertyAccess\Exception\InvalidArgumentException: "Expected argument of type "App\Entity\Artist or null", "string" given at property path "artist"." at D:\wamp64\www\app_music_events\vendor\symfony\property-access\PropertyAccessor.php line 173
  
  {
      "exception": {}
  }
  </code></pre>
  
  <p>This is the controller</p>
  
  <pre><code>/**
   * Method for editing an event
   *
   * @Route("/admin/edit/{id}", name="admin.edit", methods="GET|POST")
   * @param Request $request
   * @return \Symfony\Component\HttpFoundation\Response
   */
  public function edit(Event $event, Request $request): Response
  {
      $form = $this-&gt;createForm(EventType::class, $event);
      $form-&gt;handleRequest($request);
  
      if ($form-&gt;isSubmitted() &amp;&amp; $form-&gt;isValid()) {
          $this-&gt;em-&gt;flush();
          $this-&gt;addFlash('success', 'Le concert a été modifié avec succès !');
          return $this-&gt;redirectToRoute('admin.index');
      }
  
      return $this-&gt;render('admin/edit.html.twig', [
              'event' =&gt; $event,
              'form' =&gt; $form-&gt;createView()
          ]
      );
  }
  </code></pre>
  
  <p>I don't understand.
  I do not have this problem when I do not specify Textype in the form.</p>
  
  <p>What is the problem? Thanks</p>