我遵循这本书的快车道,第 8.7 章 Migrer la base de données。
我通过以下方式正确生成了我的 2 个实体类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
冉symfony console make:migration
,只得到:
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* 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');
}
}
为什么没有生成 SQL 代码?
我的.env
:
APP_ENV=dev
APP_SECRET=xxx
DATABASE_URL=postgresql://127.0.0.1:5432/db?serverVersion=11&charset=utf8`
命令symfony run psql
运行良好;我得到 psql 提示:
[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.
从未编辑过 Symfony 配置:
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: 'App\Entity'
alias: App