我刚开始使用symfony。我给SF4安装了树枝教义制造者...
我创建了我的数据库'Autotrader',我创建了一个迁移并迁移了它。
但是每当我尝试从数据库中获取数据时,我都会得到以下错误:

这是我使用的代码:
<?php
namespace App\Controller;
use App\Entity\Car;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class CarController extends Controller
{
public function index()
{
$repository = $this->getDoctrine()->getRepository('App:Car');
$cars = $repository->findAll();
return $this->render('Car/list.html.twig', array(
"title" => "Our cars",
'cars' => $cars
));
}
}参数config:
parameters:
# Adds a fallback DATABASE_URL if the env var is not set.
# This allows you to run cache:warmup even if your
# environment variables are not available yet.
# You should not need to change this value.
env(DATABASE_URL): ''
doctrine:
dbal:
# configure these for your database server
driver: 'mysql'
server_version: '5.7'
charset: 'utf8mb4'
dbname: 'autotrader'
host: '127.0.0.1'
port: 3306
user: 'root'
password: 'secret'
# With Symfony 3.3, remove the `resolve:` prefix
url: '%env(resolve:DATABASE_URL)%'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App发布于 2018-01-25 17:32:36
我知道问题出在哪里了。我在流浪/宅基地中运行我的应用程序,并在本地迁移,难怪找不到数据库
发布于 2018-01-25 01:11:56
这是未知的数据库错误。
您确定您已在doctrine.yml文件中提到的正确本地主机路径和端口号下创建了Autotrader db吗?
另外,在您的doctrine.yml中,将dbname: 'autotrader'替换为dbname: Autotrader,然后重试!!
https://stackoverflow.com/questions/48422863
复制相似问题