I want to create a new table in the custom schema in my PostgreSQL database. My function for creating a new table looks like this:
$platform = new PostgreSQL100Platform(); // DoctrineDBALPlatformsPostgreSQL100Platform
$schemaConfig = new SchemaConfig(); // DoctrineDBALSchemaSchemaConfig
$schemaConfig->setName('customSchemaName');
$table = new Table('t_customTableName'); // DoctrineDBALSchemaTable
$table->addColumn('columnOne', 'string');
$table->setSchemaConfig($schemaConfig);
$schema = new Schema([$table], [], $schemaConfig); // DoctrineDBALSchemaSchema
$sqls = $schema->toSql($postgre);
foreach ($sqls as $sql) {
$this->entityManager->getConnection()->executeQuery($sql);
}
Variable $sqls
will generate correct SQL, but only for default, public
schema. It looks like generated SQL ignored schema configurations.
Current generated SQL:
"CREATE TABLE t_customTableName (columnOne VARCHAR(255) NOT NULL)"
Wanted generated SQL:
"CREATE TABLE customSchemaName.t_customTableName (columnOne VARCHAR(255) NOT NULL)"
I am using Symfony 5.1, Doctrine ORM 2.7 and DBAL 2.12
Source: Symfony Questions
Was this helpful?
0 / 0