F
F
ff0xff2019-01-12 18:36:37
symfony
ff0xff, 2019-01-12 18:36:37

Why does doctrine refer to a non-existent column?

I have essence

class ProxyExchange
{
    /**
     * @ORM\Id()
     * @ORM\Column(name="id", type="guid")
     * @ORM\GeneratedValue(strategy="UUID")
     */
    private $id;

    /**
     * @ORM\ManyToMany(targetEntity="App\Entity\ProxyServer", inversedBy="ip")
     */
    private $proxy;

Okay, there is an entity with proxy servers that the proxy field should refer to
class ProxyServer
{

    /**
     * @ORM\Id()
     * @ORM\Column(type="string", length=15, options={"comment":"IPv4 proxy servers"})
     */
    private $ip;

    /**
     * @ORM\Column(type="integer", options={"comment":"Server port"})
     */
    private $port;

    /**
     * @ORM\Column(type="boolean", options={"default" : 1, "comment":"Status 1-on 0-off"})
     */
    private $active;

These are all the fields that the table with proxy servers has.
I need the proxy field in ProxyExchange to refer to the ip field in ProxyServer.
To do this, I write
@ORM\ManyToMany(targetEntity="App\Entity\ProxyServer", inversedBy="ip")

But when I try to migrate I get an error
Column name `id` referenced for relation from App\Entity\ProxyExchange towards App\Entity\ProxyServer does not exist.

I don’t understand what the hell he is trying to find an id that is not there and should not be, how can this be fixed, who knows?
  • Symfony 4
  • php 7.2

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2019-01-12
@ff0xff

Because ManyToMany must be accompanied by the JoinTable annotation.
If you do not specify it, then doctrine will add it for you with default values, and these are the id fields in one and the other entity. So he doesn't find them.
PS And inversedBy="ip" should refer to ManyToMany field with mappedBy property. In this case, you need to remove it, because. you have a unidirectional connection.
docs .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question