Symfony3.4 / Doctrine迁移 - 驱动程序中发生异常:SQLSTATE [HY000] [2002]没有这样的文件或目录

问题描述 投票:0回答:1

我正在尝试在Symfony3.4项目中运行Doctrine迁移,但是我现在已经停留了几天。有人遇到过同样的问题吗?如何使这项工作?提前致谢!

php bin/console doctrine:migrations:migrate Version20180909015642

19:03:19 ERROR     [console] Error thrown while running command 
"doctrine:migrations:migrate". Message: "An exception occured in 
driver: SQLSTATE[HY000] [2002] No such file or directory" ["exception" 
=> Doctrine\DBAL\Exception\ConnectionException { …},"command" => 
"doctrine:migrations:migrate","message" => "An exception occured in 
driver: SQLSTATE[HY000] [2002] No such file or directory"] []

In AbstractMySQLDriver.php line 103:

  An exception occured in driver: SQLSTATE[HY000] [2002] No such file 
or directory  

In PDOConnection.php line 47:

  SQLSTATE[HY000] [2002] No such file or directory  

In PDOConnection.php line 43:

  SQLSTATE[HY000] [2002] No such file or directory  

Bundle在AppKernel.php中注册

new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),

在config.yml中

doctrine_migrations:
    dir_name: "%kernel.root_dir%/DoctrineMigrations"
    namespace: Application\Migrations
    table_name: doctrine_migration_versions
    name: Application_Migrations_Default

应用程序/ DoctrineMigrations / Version20180909015642.php

<?php
declare(strict_types=1);

namespace Application\Migrations;

use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;

/**
 * Auto-generated Migration: Please modify to your needs!
 */
class Version20180909015642 extends AbstractMigration
{


    /**
     * @param Schema $schema
     */
    public function up(Schema $schema)
    {
        //...
    }

    /**
     * @param Schema $schema
     */
    public function down(Schema $schema)
    {
        //...
    }
}
symfony doctrine migration
1个回答
0
投票

控制台命令有帮助选项-h非常有用。

 php bin/console doctrine:migrations -h

已经说过,要迁移到特定的迁移文件,您应该使用最终迁移文件的时间戳,如下所述

 php bin/console doctrine:migrations:migrate 20180909015642

但是,为了执行特定的迁移文件,应该使用execute命令;喜欢以下

php bin/console doctrine:migrations:execute 20180909015642 --up

获取有关特定命令的帮助以查看完整说明和示例

php bin/console doctrine:migrations:execute -h

php bin/console doctrine:migrations:migrate -h
© www.soinside.com 2019 - 2024. All rights reserved.