I'm a bit clueless.
I would like to import data to my DB. This is a example entity:
all fields nesassary fields were filled, but doctrine tells me:
In ExceptionConverter.php line 111:
An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'pokemon_id' cannot be null
In Exception.php line 26:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'pokemon_id' cannot be null
In Statement.php line 92:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'pokemon_id' cannot be null
Here is the snipped of my entity.
/**
* @ORM\Column(type="integer")
*/
private ?int $pokemonId;
public function getPokemonId(): ?int
{
return $this->pokemonId;
}
public function setPokemonId(int $pokemonId): self
{
$this->pokemonId = $pokemonId;
return $this;
}
Where did i miss the point?
P.S.:
Maybe I should also tell that this property never can be null. And I have a relation to an
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Pokemon\Pokemon", inversedBy="pokemon_id")
*/
private $pokemon;
public function getPokemon(): ?Pokemon
{
return $this->pokemon;
}
public function setPokemon($pokemon): self
{
$this->pokemon = $pokemon;
return $this;
}
Why does SQL not take my property?
CodePudding user response:
Here is the solution.
When you have a one to many relation (in my example the pokemon) you mustn't use setpokemonId()
to store the relation, you use setPokemon()
instead. Doctrine will store the value then in the pokemon_id column.