How to enable ENUMs in Symfony 2 / Doctrine

43,476

For Symfony 2 projects, add this to the doctrine dbal configuration in app/config.yml:

doctrine:
    dbal:
        mapping_types: 
            enum:       string 

My full doctrine config looks like this:

# Doctrine Configuration
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
            set: string
            varbinary: string
            tinyblob: text

    orm:
        auto_generate_proxy_classes: %kernel.debug%
        auto_mapping: true

Code adapted from here

Then run:

app/console doctrine:schema:update --force --dump-sql --ansi

Share:
43,476
Roel Veldhuizen
Author by

Roel Veldhuizen

@roelveldhuizen

Updated on June 08, 2020

Comments

  • Roel Veldhuizen
    Roel Veldhuizen almost 4 years

    When running doctrine:mapping:import i get an error:

    Unknown database type enum requested, Doctrine\DBAL\Platforms\MySqlPlatform may not support it.

    It seems I need to set use_native_enum to true some how. However, all documentation and blog posts are refering to Symfony < 1.4. Is there any what would be the solution in Symfony 2?

  • mahen3d
    mahen3d almost 10 years
    yes this works but issue i guess is it erases all the enum types from the database when you do a "php app/console doctrine:schema:update --force"
  • Bananaapple
    Bananaapple over 5 years
    Came across this issue with a Symfony 4 app using doctrine:migrations:diff and this answer still sorts it :-)
  • Sodj
    Sodj about 5 years
    The strange thing that happened to me was that, the migration containing the enum was migrated successfully but i couldn't migrate any migration after that!
  • Raghav Rangani
    Raghav Rangani almost 5 years
    I am going to run this command php bin/console make:migration but it displaying error like: Unknown database type enum requested, Doctrine\DBAL\Platforms\MySQL57Platform may not support it.
  • John
    John about 4 years
    Worked fine for me, Thanks mate