I'm trying to get the container - and a service through it - in a migration (using Symfony 5.1.2 and doctrine/migrations 3.0.1). But when I try to create a class based on this example like this:
class Version20200717072537 extends AbstractMigration implements ContainerAwareInterface
{
use ContainerAwareTrait;
public function postUp(Schema $schema) : void
{
$fooService = $this->container->get('app.foo');
//...
}
}
... and I try to run migrations, I get a Call to a member function get() on null error.
So for some reason container is null.
I also tried replacing the use ContainerAwareTrait; with the actual setContainer function that I found in it, and it looks like the setContainer function is never called.
I'm pretty sure some time ago I was able to get the container from the migrations (maybe in Symfony 3 or 4?) based on the example I linked above, but now I don't know if this is the expected behavior in Symfony 5, or a bug, or I am doing something wrong.