首页 > 解决方案 > 在 Symfony 中使用 Doctrine DBAL 模式表示

问题描述

我一直在使用 Symfony 4+ 开发一些 Web 应用程序,我正在 MariaDB 上开发,但也希望可以选择部署到其他数据库。

当我生成数据库迁移时,它是使用 SQL 查询生成的,如下所示:

public function up(Schema $schema) {
    $this->addSql('CREATE TABLE users ...');
}

public function down(Schema $schema) {
    $this->addSql('DROP TABLE users');
}

我希望迁移使用模式表示并像这样生成:

public function createSchema() {
    $schema = new Schema();

    $table = $schema->createTable('users');
    $table->addColumn('id', 'integer', array(
        'autoincrement' => true,
    ));
    $table->setPrimaryKey(array('id'));

        return $schema;
    }
}

有没有办法配置 Symfony 或 DoctrineMigrationsBundle 以使用模式表示生成迁移?

(有点像,但不必与Laravel 的迁移完全匹配。)

标签: phpsymfonydoctrinemigrationschema

解决方案


推荐阅读