I'm currently working on a Symfony project and using Doctrine ORM. I'm trying to use a native PHP 8.1 enum for a column in one of my entities. Here is the definition of the entity and the enum:
namespace App\Entity;
use App\Enum\Complaint\Resolution;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity()
*/
class ComplaintItem
{
// ...
/**
* @ORM\Column(type="string", length=255, nullable=true, enumType=Resolution::class)
*/
private ?Resolution $resolution;
}
namespace App\Enum\Complaint;
enum Resolution: string
{
case REFUND = 'refund';
case NEW_GOODS = 'newGoods';
case REJECTED = 'rejected';
}
However, every time I generate a new migration, Doctrine generates an unnecessary ALTER TABLE statement for the resolution column:
ALTER TABLE complaint_item CHANGE resolution resolution VARCHAR(255) DEFAULT NULL
Even after I run this migration successfully, the ALTER TABLE statement for resolution appears again in the next generated migration.
I'm using Doctrine ORM 2.14, which as I understand, should support PHP 8.1 enums natively.
In order to try and resolve the issue, I've taken a few steps:
I ensured that I'm using Doctrine ORM 2.11, which supports PHP 8.1 enums. My expectation was that Doctrine should correctly generate migrations for the resolution field based on the enum, without creating repeated unnecessary changes.
I cleared the Symfony cache, thinking that some outdated metadata might be causing the problem.
Despite these steps, I'm still encountering the same issue: each time I generate a new migration, an ALTER TABLE
statement for the resolution
field is included. My expectation is that after running a successful migration, no further changes should be generated for this field until I actually modify it in my entity.
Has anyone else faced this issue with PHP 8.1 enums and Doctrine ORM <2.11 in Symfony? Any insights or solutions would be greatly appreciated.