我们在enumFooType
添加了名为\Doctrine\DBal\Types\Type::addType()
的枚举的列类型。
运行vendor/bin/doctrine-module migrations:diff
以生成将删除该列的迁移时,会引发错误:
[Doctrine\DBAL\DBALException]
Unknown column type "enumFooType" requested. Any Doctrine type that you use has to be registered with \Doctrine\DBAL\Types\Type::addType().
You can get a list of all the known types with \Doctrine\DBAL\Types\Type::getTypesMap().
If this error occurs during database introspection then you might have forgot to register all database types for a Doctrine Type.
Use AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement Type#getMappedDatabaseTypes().
If the type name is empty you might have a problem with the cache or forgot some mapping information.
我猜错了,因为数据库的foo_type
标有(DC2Type:enumFooType)
。
处理这些类型的删除的正确方法是什么?我的第一个想法是使用vendor/bin/doctrine-module migrations:generate
生成空白迁移并手动编写查询,但我想要一种更自动化的方式,如果可能的话,不要手动编写任何内容。
答案 0 :(得分:0)
<强> TL; DR:强>
在运行doctrine命令之前,DBAL类型enumFooType
的类定义应该存在(现在我已经写了这行,感觉很明显,比如&#34; duh!&#34;)。
答案很长:
经过几次回滚以及试验和错误后,我为这种操作设计了以下程序:
enumFooType
的属性。EnumFooType
文件仍然存在)。EnumFooType
类。必须在此顺序中完成的原因是因为如果先删除类型,则不会加载doctrine因为此文件丢失,导致发布的异常原来的问题。
此外,在您创建了迁移后,然后删除了该类型;如果您需要回滚该更改,则必须:
EnumFooType
存在,并且在实体类中定义类型enumFooType
的属性。