Symfony4中从已存在的数据库中生成Entity实体类

首先,在doctrine.yaml中配置好ORM的mappings。
如下

doctrine:
    dbal:
        # configure these for your database server
        driver: 'pdo_mysql'
        server_version: '5.7.24'
        charset: utf8mb4
        default_table_options:
            charset: utf8mb4
            collate: utf8mb4_unicode_ci

        url: '%env(resolve:DATABASE_URL)%'
    orm:
        auto_generate_proxy_classes: true
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true
        mappings:
            App:
                is_bundle: false
                type: annotation
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'App\Entity'
                alias: App

然后生成映射关系,也就是生成ORM

 php bin/console doctrine:mapping:import "App\Entity" xml --path=config/doctrine

生成实体类

php bin/console doctrine:mapping:import "App\Entity" annotation --path=src/Entity

生成get set 方法

php bin/console make:entity --regenerate App

参考资料:https://symfony.com/doc/current/doctrine/reverse_engineering.html

你可能感兴趣的:(Symfony4中从已存在的数据库中生成Entity实体类)