Symfony未知数据库

时间:2015-12-15 23:59:38

标签: php symfony

我有一个symfony的问题。当我执行此代码时

An exception occured in driver: SQLSTATE[HY000] [1049] Unknown database 'quiz' 

Symfony告诉我这个错误

php bin/console doctrine:database:create
Could not create database `symfony` for connection named default
An exception occurred while executing 'CREATE DATABASE `symfony`':

SQLSTATE[HY000]: General error: 1007 Can't create database 'symfony'; database exists

但是,如果我尝试创建数据库,则说数据库存在

php bin/console doctrine:schema:update --force
Nothing to update - your database is already in sync with the current entity metadata.

并且

# This file is auto-generated during the composer install
parameters:
    database_host: localhost
    database_port: ~
    database_name: symfony
    database_user: root
    database_password: ~
    mailer_transport: smtp
    mailer_host: 127.0.0.1
    mailer_user: null
    mailer_password: null
    secret: 43c1fdc9712102f8b9c3e33ed1c46befd3dae9ab

这是我的app / config / parameters.yml文件

mongodb-compass

感谢您的帮助

2 个答案:

答案 0 :(得分:0)

步骤

  1. php bin / console doctrine:database:drop --force
  2. php bin / console doctrine:database:create
  3. bin / console doctrine:schema:update --force
  4. Symfony doc http://symfony.com/doc/current/book/doctrine.html

答案 1 :(得分:0)

您的配置错误,您的数据库名称已存在symfony

将此配置放在parameters.yml

parameters: 
    database_host: localhost
    database_port: ~ 
    database_name: quiz
    database_user: root
    database_password: ~ 
    mailer_transport: 
    smtp mailer_host: 127.0.0.1
    mailer_user: null 
    mailer_password: null 
    secret:
43c1fdc9712102f8b9c3e33ed1c46befd3dae9ab

接下来在终端项目目录中执行

php bin/console doctrine:database:create

如果没有实体测验,请使用命令

创建
php bin/console doctrine:generate:entity AppBundle/Quiz

更新您的数据库

php bin/console doctrine:schema:update --force

最后一步从控制器执行你的方法来持久化并从数据库测验中刷新表测验中的对象