I have an issue with symfony. when i execute this code
$quiz = new Quiz();
$quiz->setTitle('A quiz.');
$quiz->setAuthor('Alexandre');
$quiz->setContent("Blabla…");
$em = $this->getDoctrine()->getManager();
$em->persist($quiz);
Symfony show me this error
An exception occured in driver: SQLSTATE[HY000] [1049] Unknown database 'quiz'
But if i try to create the database it says that the database exists
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
And
php bin/console doctrine:schema:update --force
Nothing to update - your database is already in sync with the current entity metadata.
This is my app/config/parameters.yml file
# 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
Thank you for your help
STEP
Symfony doc http://symfony.com/doc/current/book/doctrine.html
You have bad configuration your database name is symfony already exist
put this configuration in your 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
Next execute in terminal project directory
php bin/console doctrine:database:create
If not have the entity quiz create this with command
php bin/console doctrine:generate:entity AppBundle/Quiz
Update your database
php bin/console doctrine:schema:update --force
Final step execute you method from controller to persist and flush object in table quiz from database quiz