Using this database:
I have to make a CRUD in these tables. I made the Entities, deleting the "id" attribute, given that the tables from the database already have their own Primary Key.
An example: Entity Zonas:
<?php
namespace App\Entity;
use App\Repository\ZonasRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ZonasRepository::class)]
class Zonas
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $cod_zona = null;
#[ORM\Column(length: 255)]
private ?string $nombre_zona = null;
public function getCodZona(): ?int
{
return $this->cod_zona;
}
public function setCodZona(int $cod_zona): static
{
$this->cod_zona = $cod_zona;
return $this;
}
public function getNombreZona(): ?string
{
return $this->nombre_zona;
}
public function setNombreZona(string $nombre_zona): static
{
$this->nombre_zona = $nombre_zona;
return $this;
}
}
I used the command make:crud to create a CRUD on the tables, but I don't know how to generate new numbers of the Primary Keys within Symfony. For example: when I create a new Zone. I got this exception:
An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0' for key 'PRIMARY'
Obviously, this is because the cod_zona attribute isn't autogenerated. How can I do this?
I created a crud, I didn't make any doctrine migrations because the database was already defined (FK and PK included). I need to create these new codes when I create a new instance: ZONAS: The max zona number +1.
EQUIPO: Is a integer composed by the number of the zone and another number starting by 1. If you got 4 EQUIPO in a zone, the next EQUIPO you create is 15 (ZONA 1, EQUIPO 5).
JUGADORES: I a integer composed by the number of the EQUIPO and another number starting by 1 (the same way as EQUIPO with ZONAS).
PARTIDOS: The same as ZONAS: the max PARTIDOS +1.
