如何从控制台命令创建新类别

How to create a new Category from Console Command

我正在尝试通过 Magento 2 上的控制台命令以编程方式生成一些类别,但 Magento 在命令执行后立即响应此错误:

[Magento\Framework\Exception\LocalizedException]                          
Class Magento\Catalog\Api\Data\CategoryExtensionInterface does not exist

Magento 上存在错误引用的接口。 重现错误的代码非常简单

class MyCommand extends Command {

[...initialization block...]

protected function execute(InputInterface $input, OutputInterface $output)
{
    $this->objectManager->create(\Magento\Catalog\Model\Category::class);
}

有人以前见过这个错误吗?

请检查 var/generation 的文件权限。