B
B
BonBon Slick2018-10-06 11:44:14
symfony
BonBon Slick, 2018-10-06 11:44:14

Running migration in console command?

I made my own entity generator, after generating files, 2 commands occur

/**
   * @throws Exception
   */
  private function migrateNewEntity() {
    // Generate database migration fore new Entity
    /** @var Application $application */
    $application = $this->getApplication();
    /** @var MigrationsDiffDoctrineCommand|Command $command */
    $command    = $application->find('doctrine:migrations:diff');
    $arguments  = [
      'command' => 'doctrine:migrations:diff',
    ];
    $greetInput = new ArrayInput($arguments);
    $command->run($greetInput, new NullOutput());

    // migrate new migration
    /** @var MigrationsMigrateDoctrineCommand|Command $command */
    $command    = $application->find('doctrine:migrations:migrate');
    $arguments  = [
      'command' => 'doctrine:migrations:migrate',
    ];
    $greetInput = new ArrayInput($arguments);
    $command->run($greetInput, new NullOutput());
  }

Everything falls still on the first command
In MappingException.php line 64:
                                                                                                      
  No mapping file found named 'Testik.orm.xml' for class 'App\Entity\Testik'.

Testik is the name of the entity, strange, trying to do
console doctrine:schema:validate 

Mapping
-------                                                                
 [OK] The mapping files are correct.          
Database
--------                                                                                               
 [ERROR] The database schema is not in sync with the current mapping file.

It can be seen that the files have a mapping. I manually do migrations:diff + migrations:migrate to work everything out.
Mapping files, like all others, are created before the migration starts.
Why when a command is called in another command gives an error that the file does not exist when it exists?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question