2
votes

I currently struggling with problem on my web project.

I have created a "Voucher" entity through "bin/console make:entity" command and i would like to make a migration to write to to the database. But Doctrine throws a weird error and I dont know how to fix it. Can anyone help me?

Symfony 4.4.10 & Doctrine 1.4

The error:

In ClassNameGenerator.php line 14: Argument 1 passed to Doctrine\Migrations\Generator\ClassNameGenerator::generateClassName() must be of the type string, null given, called in /var/www/skodanezajit/vendor/doctrine/migrations/lib/Doctrine/Migrations/Tool s/Console/Command/DiffCommand.php on line 139

Voucher entity:

<?php

namespace App\Entity;

use App\Repository\VoucherRepository;
use DateTime;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass=VoucherRepository::class)
 */
class Voucher
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private $code;

    /**
     * @ORM\Column(type="datetime")
     */
    private $dateCreated;

    /**
     * @ORM\Column(type="datetime")
     */
    private $lastsTo;

    /**
     * @ORM\Column(type="integer")
     */
    private $value;

    /**
     * @ORM\Column(type="boolean", nullable=true)
     */
    private $used;

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getCode(): ?string
    {
        return $this->code;
    }

    public function setCode(string $code): self
    {
        $this->code = $code;

        return $this;
    }

    public function getDateCreated(): ?\DateTimeInterface
    {
        return $this->dateCreated;
    }

    public function setDateCreated(\DateTimeInterface $dateCreated): self
    {
        $this->dateCreated = new \DateTime('now');

        return $this;
    }

    public function getLastsTo(): ?\DateTimeInterface
    {
        return $this->lastsTo;
    }

    public function setLastsTo(\DateTimeInterface $lastsTo): self
    {
        $this->lastsTo = new \DateTime('now +6 months');

        return $this;
    }

    public function getValue(): ?int
    {
        return $this->value;
    }

    public function setValue(int $value): self
    {
        $this->value = $value;

        return $this;
    }

    public function getUsed(): ?bool
    {
        return $this->used;
    }

    public function setUsed(?bool $used): self
    {
        $this->used = $used;

        return $this;
    }
}

Thanks a lot!

1
Did you generate migrations before and this is the problem only with this class? What command are you using? What is your migrations config? - blahy
Yeah, I already created an entity and everything went smooth. This is first time anything similar happened. I used "make:entity" and then "make:migration", because there's no migrations on my current local environment. My migrations config is all commented, I thought the "symfony/flex" will handle that. Will it or can this be the problem? - Jakub Novák
I dont see anything weird with this entity. According to documentation of migration bundle you should have config and flex should install it if it was not in place already symfony.com/doc/master/bundles/DoctrineMigrationsBundle/… . For example migrations_paths at least one is required. I dont know why it is commented out for you. - blahy
I cannot reproduce the error on my side. Desperate suggestions: Have you tried to clear the cache? Did you do a composer update? it seems to be failing during the Doctrine Migrations Diff command.. Have you tried to run directly php bin/console doctrine:migrations:diff instead of php bin/console make:migration ? - Gillu13

1 Answers

4
votes

Error come from an inexisting Migrations Folder.

Try to add this in you config/packages/doctrine_migrations.yaml:

doctrine_migrations:
    migrations_paths:
        DoctrineMigrations: 'src/Migrations'

And create src/Migrations folder if it does not exist.