Disable foreign keys in Doctrine migrants

I am using the NDBCLUSTER mechanism on a MySQL database. I added a class for wrapping Connection

and adding an engine option:

namespace AppBundle\DBAL;

use Doctrine\DBAL\Connection as BaseConnection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Configuration;
use Doctrine\Common\EventManager;

class Connection extends BaseConnection
{
    public function __construct(array $params, Driver $driver, Configuration $config = null, EventManager $eventManager = null)
    {

        if (isset($params['driverOptions']['engine'])) {
            $params['defaultTableOptions']['engine'] = $params['driverOptions']['engine'];
        }

        return parent::__construct($params, $driver, $config, $eventManager);
    }
}

      

I am defining a parameter engine

in the file config.yml

:

doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                driver:   "%database_driver%"
                host:     "%database_host%"
                port:     "%database_port%"
                dbname:   "%database_name%"
                user:     "%database_user%"
                password: "%database_password%"
                charset:  UTF8
                wrapper_class: AppBundle\DBAL\Connection
                options:
                    engine: NDBCLUSTER
    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        default_entity_manager: default
        entity_managers:
            default:
                connection: default
                mappings:
                    AppBundle:  ~

      

Then, if I execute php app/console doctrine:migrations:diff

, the NDBCLUSTER mechanism is added to the statements CREATE

. However, foreign keys are added as well, and NDBCLUSTER does not accept foreign keys. Is there a way to disable foreign keys (I mean without writing them to migration files)?

+3


source to share


1 answer


I disabled foreign keys by implementing my own platform_service for this connection:

namespace AcmeBundle\Doctrine;
use Doctrine\DBAL\Platforms\MySQL57Platform;

class CustomMySQLPlatform extends MySQL57Platform
{

    public function supportsForeignKeyConstraints()
    {
        return false;
    }

    public function supportsForeignKeyOnUpdate()
    {
        return false;
    }
}

      

Service definition in services.yml:



    acme.dbal.service.custom_mysql_platform:
        class: AcmeBundle\Doctrine\CustomMySQLPlatform

      

Doalrine DBAL definition in config.yml:

doctrine:
    dbal:
        connections:
            default:
                ....
                platform_service: acme.dbal.service.custom_mysql_platform

      

0


source







All Articles