使用主义orm symfony创建数据库时出错

时间:2019-04-02 11:08:39

标签: symfony doctrine-orm composer-php

当我尝试使用命令创建数据库

$ php bin/console doctrine:database:create

我得到那些错误


2019-04-02T12:45:01+02:00 [error] Error thrown while running command "doctrine:d
atabase:create". Message: "An exception occurred in driver: SQLSTATE[HY000] [104
5] Access denied for user 'root'@'localhost' (using password: YES)"

In AbstractMySQLDriver.php line 93:

  An exception occurred in driver: SQLSTATE[HY000] [1045] Access denied for u
  ser 'root'@'localhost' (using password: YES)


In PDOConnection.php line 31:

  SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using pas
  sword: YES)


In PDOConnection.php line 27:

  SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using pas
  sword: YES)

我卸载了xmapp,composer,symbony,然后再次安装了它们。

  • PHP版本7.3.3
  • Composer 1.8.4版本
  • Symfony CLI版本4.3.3

按照以下步骤安装orm学说 https://symfony.com/doc/current/doctrine.html

 composer require symfony/orm-pack
 composer require --dev symfony/maker-bundle

修改后的 .env 文件

DATABASE_URL=mysql://root:123456@127.0.0.1:3306/test

然后执行

php bin/console doctrine:database:create

然后,错误来了。

2 个答案:

答案 0 :(得分:1)

.env文件看起来像这样:

DATABASE_URL=mysql://root:123456@127.0.0.1:3306/articles

我刚刚删除了密码,问题得以解决:

DATABASE_URL=mysql://root@127.0.0.1:3306/articles

现在已创建数据库。

答案 1 :(得分:-2)

验证一次是否安装了理论软件包?

   [
// title 
            't_id' => ['type' => 'integer'],
            'name' =>['type' =>'keyword'],
          ...

            'genres' =>[
                'type' =>'nested',
                'properties' =>[
                    'genre' =>['type' =>'keyword'],
                ]
            ],
             ...

            // what type is this... title/episode.
            'type' => ['type' =>'keyword'],

            // joins...
             "joinField" => [
                 'type' =>'join',
                 'relations' =>[
                     'title' =>'episodes'
                 ]
             ],

            // Child , episode.
            'e_id' => ['type' => 'long'],

            'episode' => ['type' => 'integer'],
            'season' => ['type' => 'integer'],
            'episode_hash' => ['type' => 'keyword'],
            'airdate' => ['type' => 'date'],

            // Has subs + languages.
            'has_subs' => ['type' => 'byte'],
            'languages' => [
                'type' => 'nested',
                'properties' => [
                    'l_id' => ['type' => 'integer'],
                    'name' => ['type' => 'keyword'],
                    'flag' => ['enabled' => false]
                ]
            ]
    ]

然后,通过在项目的app / AppKernel.php文件中添加以下行来启用捆绑软件:

$ composer require doctrine/doctrine-bundle