0

I come here for the first time because I have a problem when I want to create my database with doctrine and Symfony. When I want export my classes in my database I have this problem. I think everything is okay, doctrine find my base but can't create it. Also, I created my database named "symfony" in phpmyadmin.

I hope someone can help me, thank you so much :).

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

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

Configuration file:

parameters:
    database_driver: pdo_mysql
    database_host: 127.0.0.1
    database_port: null
    database_name: symfony
    database_user: root
    database_password: null
    mailer_transport: smtp
    mailer_host: 127.0.0.1
    mailer_user: null
    mailer_password: null
    locale: en
    secret: 255a33a57b471045aa29326785659c6b0
    database_path: null

# Doctrine Configuration
doctrine:
    dbal:
        driver:   "%database_driver%"
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8
        # if using pdo_sqlite as your database driver, add the path in parameters.yml
        # e.g. database_path: "%kernel.root_dir%/data/data.db3"
        # path:     "%database_path%"

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        auto_mapping: true
CSchulz
  • 10,882
  • 11
  • 60
  • 114
wbrancaleone
  • 11
  • 1
  • 1
  • 1
    What part of the error message `Can't create database 'symfony'; database exists` are you having trouble with? – fvu Mar 01 '14 at 18:52
  • Could not create database for connection named `symfony` An exception occurred while executing 'CREATE DATABASE `symfony`': SQLSTATE[HY000]: General error: 1007 Can't create database 'symfony'; database exists – wbrancaleone Mar 01 '14 at 19:03
  • Well it confirms that the database exists, so maybe start by deleting or renaming the existing db? – fvu Mar 01 '14 at 19:04
  • If you want to delete your database run: `C:\wamp\www\Symfony>php app/console doctrine:database:drop` – Mr. Radical Mar 01 '14 at 19:12
  • Okay, I thought all the tables will be create with the base but no. It's just the base. Thank you, I'm done with that ;). – wbrancaleone Mar 01 '14 at 19:21
  • @wbrancaleone if your question is solved could you be so kind and accept or upvote my answer below? – Mr. Radical Mar 01 '14 at 19:55

1 Answers1

2

To summarize:

The error informs you that a database with the same name was already created. There are three options:

(1) Delete your current database without saving it, using MySQL command line. If you want to delete your database run: DROP database name_database

(2) Delete the database without saving it, using console: C:\wamp\www\Symfony>php app/console doctrine:database:drop

(3) In the case you like to save the content of your current database. Rename you current database. As far as I know you cannot do this directly. This is a work around. First, create a new database using command line: CREATE DATABASE name_old_database;. Second, copy all tables to the new database RENAME TABLE name_database.name_table TO name_old_database.name_table;. Finally,DROP DATABASE name_database See further info: How do I quickly rename a MySQL database (change schema name)?

Community
  • 1
  • 1
Mr. Radical
  • 1,847
  • 1
  • 19
  • 29