Best strategy for migrating mysql enums to doctrin

2019-07-22 20:17发布

I am currently in the process of migrating a legacy app over to symfony2, the problem is that I have a lot of mysql enum columns, I know that doctrine does not support enum data types and that one workaround is to store as a string but I would really lose the ability to properly sort the data because varchars are a lot slower, I do have a lot of tables with the enum data types and modifying the schema would be really hard, what are my options?? What can you suggest that will make a transition to symfony2 a lot smoother?

2条回答
爷、活的狠高调
2楼-- · 2019-07-22 20:43

Try this it worked for me

http://symfony.com/doc/current/reference/configuration/doctrine.html#reference-dbal-configuration

in the app/config/config.yml file add

    mapping_types:
       enum: string

e.g below

doctrine:
dbal:
    driver:   %database_driver%
    host:     %database_host%
    port:     %database_port%
    dbname:   %database_name%
    user:     %database_user%
    password: %database_password%
    charset:  UTF8
    mapping_types:
        enum: string

then you can use e.g.

@ORM\Column(type="string", columnDefinition="ENUM('A', 'B')")
查看更多
姐就是有狂的资本
3楼-- · 2019-07-22 20:45

You have two solution

  • Solution 1: Mapping to Varchars
  • Solution 2: Defining a Type

for more information please consult this link: Mysql Enums doctrine

查看更多
登录 后发表回答