I follow the book the fast track, chapter ‘8.7 Migrer la base de données’.
I have my 2 Entities classes properly generated via symfony console make:entity
:
ls -1 src/Entity/Co*
src/Entity/Comment.php
src/Entity/Conference.php
https://pastebin.com/6RJmQTEg
https://pastebin.com/XwZ7csS3
Ran symfony console make:migration
, get only :
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use DoctrineDBALSchemaSchema;
use DoctrineMigrationsAbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20200322201522 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on 'postgresql'.');
$this->addSql('CREATE SCHEMA public');
}
}
Why there’s no SQL code generated ?
My .env
:
APP_ENV=dev
APP_SECRET=xxx
DATABASE_URL=postgresql://127.0.0.1:5432/db?serverVersion=11&charset=utf8`
The command symfony run psql
run well; I get psql prompt:
[mevatlave:~/sources/guestbook] master* ± symfony run psql
psql (11.7 (Debian 11.7-0+deb10u1))
Type "help" for help.
main=#
symfony -V
Symfony CLI version v4.13.3 (Thu Mar 19 15:24:08 UTC 2020)
php bin/console debug:container --env-vars
Symfony Container Environment Variables
=======================================
-------------- --------------- ----------------------------------------------------------------
Name Default value Real value
-------------- --------------- ----------------------------------------------------------------
APP_SECRET n/a "4ec3efda62f1b3001e78459335893c3f"
DATABASE_URL n/a "postgresql://127.0.0.1:5432/db?serverVersion=11&charset=utf8"
-------------- --------------- ----------------------------------------------------------------
// Note real values might be different between web and CLI.
Never edited Symfony config :
cat config/packages/doctrine.yaml
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
# IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file)
#server_version: '5.7'
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'AppEntity'
alias: App
2
Answers
OK, found a bug in the book, the DSN is wrong :
DATABASE_URL=postgresql://127.0.0.1:5432/db?serverVersion=11&charset=utf8
Now :
DATABASE_URL=postgresql://main:[email protected]:5432/db?serverVersion=11&charset=utf8
Lack of username/password. Now symfony
console make:migration
works wellTry clearing your cache first.
Otherwise try this:
You need doctrine:migrations:diff. That will generate a new migration pre-filled with the SQL that you would get from a doctrine:schema:update
So:
Then you go check the newly created file and if all is ok you execute it with:
If you then want to go back because you made a mistake or whatever