2016-12-12 46 views
1

我們在\Doctrine\DBal\Types\Type::addType()上添加了一個名爲enumFooType的枚舉的列類型。刪除列時使用原則遷移

當運行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. 

我猜測拋出的錯誤,因爲該數據庫有標有(DC2Type:enumFooType)一個foo_type

處理這些刪除類型的正確方法是什麼?我的第一個想法是使用vendor/bin/doctrine-module migrations:generate生成空白遷移並手動編寫查詢,但我希望採用更自動化的方式,如果可能的話不要手動編寫任何內容。

回答

0

TL; DR:

爲DBAL型enumFooType運行學說命令之前,應該存在的類定義(現在我已經寫了這條線時,感覺那種明顯的,像「咄!」) 。

龍答:

一對夫婦回滾和試錯後,我設計了以下程序進行這種操作:

  1. 從實體類中刪除的enumFooType財產。
  2. 創建遷移(到目前爲止,EnumFooType文件仍然存在)。
  3. 刪除包含此dbal類型定義的EnumFooType類。

它在這個爲了做的原因是因爲如果你先刪除類型,原則不會因爲負荷這個文件丟失,從而導致張貼在原來的問題除外。

而且,在創建遷移後,再刪除的類型;如果你需要回滾的變化,你必須:

  1. 恢復到以前提交,使EnumFooType存在,enumFooType類型的屬性在實體類中定義。
  2. 運行遷移命令回滾。