# Doctrine command in Mezzio application

**URL:** <https://discourse.laminas.dev/t/doctrine-command-in-mezzio-application/3386>\
**Category:** Mezzio\
**Tags:** doctrine\
**Created:** [July 6, 2023, 8:42pm UTC](https://discourse.laminas.dev/t/doctrine-command-in-mezzio-application/3386 "2023-07-06T20:42:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stefan81](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@Stefan81](https://discourse.laminas.dev/u/Stefan81)\
**Post date:** [July 6, 2023, 8:42pm UTC](https://discourse.laminas.dev/t/doctrine-command-in-mezzio-application/3386/1 "2023-07-06T20:42:10Z")

</div>

I’m currently working on a Mezzio application and I’m trying to figure out the best way to use Doctrine commands like migrations. I’ve been reading the documentation, but I’m still a bit confused.  
Can anyone offer some advice? how i can configure doctrine command in Mezzio application

Thanks,

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [July 6, 2023, 9:12pm UTC](https://discourse.laminas.dev/t/doctrine-command-in-mezzio-application/3386/2 "2023-07-06T21:12:37Z")

</div>

> [@Stefan81](#):
>
> I’ve been reading the documentation…

The official documentation of Mezzio does not contain anything about migrations with Doctrine, so which documentation do you mean?

If you use “[Doctrine ORM Module for Laminas](https://www.doctrine-project.org/projects/doctrine-module.html)” then it should be something like:

```bash
./vendor/bin/doctrine-module migrations:list

```

> **[Doctrine CLI - Doctrine Doctrine Module for Laminas](https://www.doctrine-project.org/projects/doctrine-module/en/5.3/cli.html#doctrine-cli)**
>
> Doctrine Doctrine Module for Laminas Documentation: Doctrine CLI

---

<div class="post-metadata">

**Author:** ![george](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/george/32/676_2.png) [@george](https://discourse.laminas.dev/u/george)\
**Post date:** [July 11, 2023, 3:21pm UTC](https://discourse.laminas.dev/t/doctrine-command-in-mezzio-application/3386/3 "2023-07-11T15:21:37Z")

</div>

If you’re using doctrine/migrations standalone, I will normally drop something like this into `config/cli-config.php` and then run `vendor/bin/doctrine` and `vendor/bin/doctrine-migrations`

```php
<?php

declare(strict_types=1);

use Doctrine\DBAL\Connection;
use Doctrine\Migrations\Configuration\Configuration;
use Doctrine\Migrations\Tools\Console\Helper\ConfigurationHelper;
use Doctrine\ORM\Tools\Console\ConsoleRunner;

chdir( __DIR__. '/../');
require __DIR__. '/../vendor/autoload.php';

$container = require __DIR__. '/container.php';
$entityManager = $container->get('doctrine.entity_manager.orm_default');
$helperSet = ConsoleRunner::createHelperSet($entityManager);

/**
 * Migrations
 */
$migrationConfigHelper = new ConfigurationHelper(
    $container->get(Connection::class),
    $container->get(Configuration::class)
);
$helperSet->set($migrationConfigHelper, 'configuration');

return $helperSet;

```

Obviously, you’ll need to make sure that the services you fetch from the container here are using the correct service identifiers / FQCNs

---

<div class="post-metadata">

**Author:** ![Stefan81](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@Stefan81](https://discourse.laminas.dev/u/Stefan81)\
**Post date:** [July 12, 2023, 9:22pm UTC](https://discourse.laminas.dev/t/doctrine-command-in-mezzio-application/3386/4 "2023-07-12T21:22:43Z")

</div>

thank you very much…that will be good point to start…what i am trying to use laminas-cli to executed doctrine command…somthing like factory for the doctrine commands(inclusive migrations)…

---

<div class="post-metadata">

**Author:** ![Stefan81](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@Stefan81](https://discourse.laminas.dev/u/Stefan81)\
**Post date:** [July 12, 2023, 9:23pm UTC](https://discourse.laminas.dev/t/doctrine-command-in-mezzio-application/3386/5 "2023-07-12T21:23:38Z")

</div>

thank for answes…but this doctrine module is only for laminas and will not working with Mezzio? or?

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [July 12, 2023, 9:33pm UTC](https://discourse.laminas.dev/t/doctrine-command-in-mezzio-application/3386/6 "2023-07-12T21:33:05Z")

</div>

> [@Stefan81](#):
>
> …but this doctrine module is only for laminas and will not working with Mezzio? or?

Don’t let the name mislead you, because if a config provider class is included, then you can also use this in Mezzio:

> <https://github.com/doctrine/DoctrineModule/blob/d02db3d322051c2fceee2ea54bd2945f0fc1bb72/src/ConfigProvider.php#L14-L17>

> <https://github.com/doctrine/DoctrineORMModule/blob/05751818bb579c94ca8ff077332f98f9abf15021/src/ConfigProvider.php#L7-L10>

Or check the configuration for Composer:

> <https://github.com/doctrine/DoctrineModule/blob/d02db3d322051c2fceee2ea54bd2945f0fc1bb72/composer.json#L110-L115>

> <https://github.com/doctrine/DoctrineORMModule/blob/05751818bb579c94ca8ff077332f98f9abf15021/composer.json#L45-L50>
