wbrancaleone
wbrancaleone

Reputation: 11

Error create database with shell

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

Upvotes: 0

Views: 4585

Answers (1)

Mr. Radical
Mr. Radical

Reputation: 1838

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)?

Upvotes: 2

Related Questions