symfony根据数据库生成实体

2019-07-02 17:18:00
CJL
原创
3407

参考文章:

https://symfony.com/doc/current/doctrine/reverse_engineering.html How to Generate Entities from an Existing Database

https://www.jianshu.com/p/75fc86ec98aa symfony 创建数据库映射时报错: Unknown database type enum requested

https://codeday.me/bug/20181110/383025.html symfony – Doctrine2忽略数据库表


基础命令:

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

App\Entity 命名空间

annotation 生成方式

--path 生成路径

生成getter/setter方法

php bin/console make:entity --regenerate  App\\Entity\\UserModule

也可以使用phptorm生成getter、setter方法

可能出现的问题:

1、不想生成全部表

添加参数进行过滤,过滤的是匹配类名 --filter=User

2、过滤不符合规则的表

修改doctrine配置,过滤表,添加 

schema_filter: ~^(?!Table1)~

3、提示数据类型不支持

修改doctrine配置,添加类型映射表,添加 

mapping_types:
    enum: string
    set: string
    varbinary: string
    tinyblob: text

4、数据库表太多,仅生成想要的表

修改doctrine配置,schema_filter规则临时仅允许特定表

schema_filter: ~^(user)$~

5、连接其他数据库

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


最终样例如下:


发表评论
评论通过审核后显示。
流量统计