Reputation: 3647
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
Upvotes: 3
Views: 6006
Reputation: 1107
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
Upvotes: 0
Reputation: 11
Try this link:
vendor/bin/doctrine-module orm:schema-tool:create
User doctrine-module instead of doctrine.
Upvotes: 1