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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Symfony3.4 / Doctrine迁移 - 驱动程序中发生异常:SQLSTATE [HY000] [2002]没有这样的文件或目录相关的知识,希望对你有一定的参考价值。

我正在尝试在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" 
=> DoctrineDBALExceptionConnectionException { …},"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 DoctrineBundleMigrationsBundleDoctrineMigrationsBundle(),

在config.yml中

doctrine_migrations:
    dir_name: "%kernel.root_dir%/DoctrineMigrations"
    namespace: ApplicationMigrations
    table_name: doctrine_migration_versions
    name: Application_Migrations_Default

应用程序/ DoctrineMigrations / Version20180909015642.php

<?php
declare(strict_types=1);

namespace ApplicationMigrations;

use DoctrineDBALMigrationsAbstractMigration;
use DoctrineDBALSchemaSchema;

/**
 * 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)
    {
        //...
    }
}
答案

控制台命令有帮助选项-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

以上是关于Symfony3.4 / Doctrine迁移 - 驱动程序中发生异常:SQLSTATE [HY000] [2002]没有这样的文件或目录的主要内容,如果未能解决你的问题,请参考以下文章

Symfony 3.4没有元数据类来处理错误

如何使用 Doctrine 更改列字符集和排序规则?

首先在doctrine查询构建器中选择完全匹配

从 Symfony 3.4 迁移到 Symfony 4.4 后,自定义投票器无法按预期工作

Symfony-Doctrine从不同数据库导入数据的最佳方式

Symfony 和 Doctrine 使迁移无效