G
G
gitdev2019-01-02 17:32:21
symfony
gitdev, 2019-01-02 17:32:21

How to solve problem with on delete cascade not working in Symfony 4 on many to many?

Throws an error when uninstalling the agent.
Connection:

/**
     * Many Realties have Many Agents.
     *
     * @ManyToMany(targetEntity="App\Metrag\AppBundle\Entity\Realty", cascade={"persist", "remove"})
     * @JoinTable(
     *      joinColumns={@JoinColumn(name="agent_id", referencedColumnName="id",  onDelete="CASCADE")},
     *      inverseJoinColumns={@JoinColumn(name="realty_id", referencedColumnName="id",  onDelete="CASCADE")}
     * )
     */
    private $realties;

Mistake:
SQLSTATE[23503]: Foreign key violation: 7 ERROR:  update or delete on table "agents" violates foreign key co  
  nstraint "fk_89bf0de13414710b" on table "agent_realties"                                                      
  DETAIL:  Key (id)=(2) is still referenced from table "agent_realties".                                        
                                                                                                                

In PDOConnection.php line 62:
                                                                                                                
  SQLSTATE[23503]: Foreign key violation: 7 ERROR:  update or delete on table "agents" violates foreign key co  
  nstraint "fk_89bf0de13414710b" on table "agent_realties"                                                      
  DETAIL:  Key (id)=(2) is still referenced from table "agent_realties".                                        
                                                                                                                

In PDOConnection.php line 60:
                                                                                                                
  SQLSTATE[23503]: Foreign key violation: 7 ERROR:  update or delete on table "agents" violates foreign key co  
  nstraint "fk_89bf0de13414710b" on table "agent_realties"                                                      
  DETAIL:  Key (id)=(2) is still referenced from table "agent_realties".

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
grinat, 2019-01-02
@grinat

Postgres? Remove the keys, or write the trigger yourself, or delete the parent, then all the menus will be deleted without errors.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question