3

I am following this tutorial. http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/getting-started.html

I am using mysql instead of sqlite.

Following command should create the database.

php vendor/bin/doctrine orm:schema-tool:create

But it is not creating any. If i manually create the database, following command works fine

php vendor/bin/doctrine orm:schema-tool:update --force

Any idea why that command is not working?

Doctrine version 2.4.1

2
  • what is the error msg in the cli after this: php vendor/bin/doctrine orm:schema-tool:create ?
    – Momin
    Jan 1, 2014 at 20:43
  • did you tell your config all about your mysql connection? database, user, password ...
    – zavalit
    Apr 19, 2014 at 15:00

2 Answers 2

1

Try this link:

vendor/bin/doctrine-module orm:schema-tool:create

User doctrine-module instead of doctrine.

2
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes.
    – juliocesar
    Jul 12, 2014 at 5:19
  • this saved my life. Nov 7, 2016 at 15:08
0

I was faced with a similar issue and found that the command below

php vendor/bin/doctrine orm:schema-tool:create

Doesn't create the DB itself, it only creates the schema/tables.

I solved this by doing the following:

<?php
include 'bootstrap.php';
use Doctrine\ORM\Tools\Console\ConsoleRunner,
    Doctrine\ORM\EntityManager;

try {
    $entityManager->getConnection()->connect();
}
catch(Exception $ex) {
    $connection = EntityManager::create([
        'driver'   => 'pdo_mysql',
        'host'     => MYSQL_HOST,
        'user'     => MYSQL_USERNAME,
        'password' => MYSQL_PASSWORD,
        'charset' => 'UTF8'
    ], $config)->getConnection();
    $connection->executeUpdate('CREATE DATABASE '.MYSQL_DATABASE.' CHARACTER SET utf8 COLLATE utf8_general_ci');
}
return ConsoleRunner::createHelperSet($entityManager);
?>

Basically the script attempts to connect to the specified database, if that fails it attempts to create the database (assuming that the user is allowed to perform database creation that is - might be prudent to delete this file after deployment).

Source: http://www.cstruter.com/blog/395

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.