Doctrine2: How to set all tables to collate with UTF8

前端 未结 14 1046
夕颜
夕颜 2020-12-08 02:55

I am using Doctrine with Symfony2. My config.yml file looks something like this:-

Doctrine Configuration

doctrine:
    dbal:
        driver: %data         


        
14条回答
  •  旧巷少年郎
    2020-12-08 03:36

    if you are looking for a way to have migrations be created correctly you should setup the connection

    you can set the default_table_options connection option to achieve this: in symfony this is done through:

    doctrine:
        dbal:
            default_table_options:
                charset: utf8
                collate: utf8_general_ci
    

    for those looking to do it in plain doctrine this translates to doctrine connection option defaultDatabaseOptions, and is passed to the entity manager together with your database credentials etc:

    [
        ...
        'driver' => ...
        'user' => ...
        ...
        'defaultDatabaseOptions' => [
             'charset' => 'utf8',
             'collate' => 'utf8_general_ci'
        ]
    ]
    

提交回复
热议问题