我在 MySQL 数据库中使用 NDBCLUSTER 引擎。我添加了一个用于包装Connection
和添加引擎选项的类:
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);
}
}
我在文件中定义了engine
选项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: ~
然后,如果我执行php app/console doctrine:migrations:diff
NDBCLUSTER 引擎,则将其添加到CREATE
语句中。但是,也添加了外键,并且 NDBCLUSTER 不接受外键。有什么方法可以禁用外键(我的意思是,不要将它们写在迁移文件中)?