我开始学习Symfony2,我想使用Doctrine在我的postgres数据库中创建表。我安装了postgres并按照以下步骤操作:
sudo -i -u postgres
我创建了名称为test的用户:test并输入超级用户
createuser --interactive
createdb test
我使用密码测试创建了用户测试
adduser test
我在symfony2中的parameters.yml看起来像这样:
parameters:
database_driver: pdo_pgsql
database_host: 127.0.0.1
database_port: null
database_name: test
database_user: test
database_password: test
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
我也有这样的实体:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="product")
*/
class Product
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length=100)
*/
protected $name;
/**
* @ORM\Column(type="decimal", scale=2)
*/
protected $price;
/**
* @ORM\Column(type="text")
*/
protected $description;
}
然后我在终端输入了这个表述:
php app/console doctrine:generate:entities AppBundle
我收到了这个警告:
[Doctrine\DBAL\Exception\ConnectionException]
An exception occured in driver: SQLSTATE[28000] [1045] Access denied for us
er 'test'@'localhost' (using password: YES)
[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[28000] [1045] Access denied for user 'test'@'localhost' (using pas
sword: YES)
[PDOException]
SQLSTATE[28000] [1045] Access denied for user 'test'@'localhost' (using pas
sword: YES)
我该怎么做才能解决这个问题?
编辑:
我意识到我已连接到mysql数据库而且我不知道为什么。我怎么能改变这个?
答案 0 :(得分:2)
我们的一位开发人员上周遇到了这个问题。
你的parameters.yml似乎很好,但如果你有&#34;标准&#34; config.yml,它没有指定database_driver
#app/config/config.yml
[...]
# Doctrine Configuration
doctrine:
dbal:
driver: "%database_driver%" # <---- Add this line ;)
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
[...]