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

时间:2018-09-11 19:33:59

标签: symfony doctrine migration

我正在尝试在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  

捆绑包已在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

app / 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)
    {
        //...
    }
}

1 个答案:

答案 0 :(得分: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