如何在 Symfony 4 中定义整个数据库模式?
How to define entire database schema in Symfony 4?
有没有办法在 Symfony 4 中一次定义完整的数据库模式?
我知道可以使用 make:entity
和 make:migration
命令创建个人 entities/objects,但我想知道我是否可以一次定义整个架构然后使用它来构建关联的实体和数据库。
我记得在 Symfony 的早期版本中,可以在 YAML 文件中定义整个模式,然后只需发出一个构建命令。
是的,您可以使用任何支持的映射格式(例如 YAML 或 XML)和 declare mappings location in Doctrine configuration. After that you will be able to use any Doctrine console tools to generate and update schema. You can also use tools for reverse engineering mappings from already available database and to convert 格式之间的映射
创建完整的数据库模式映射
请注意,Symfony 应用程序中的 Doctrine 命令名称与 Doctrine 原生提供的名称不同。您需要使用:
doctrine:schema:validate
用于架构验证
doctrine:schema:create
用于初始模式生成,随后根据您的需要使用 --dump-sql
或 --force
调用 doctrine:schema:update
doctrine:mapping:convert
对可用数据库进行逆向工程(使用 --from-database
选项)或在需要时在映射类型之间进行转换。
有没有办法在 Symfony 4 中一次定义完整的数据库模式?
我知道可以使用 make:entity
和 make:migration
命令创建个人 entities/objects,但我想知道我是否可以一次定义整个架构然后使用它来构建关联的实体和数据库。
我记得在 Symfony 的早期版本中,可以在 YAML 文件中定义整个模式,然后只需发出一个构建命令。
是的,您可以使用任何支持的映射格式(例如 YAML 或 XML)和 declare mappings location in Doctrine configuration. After that you will be able to use any Doctrine console tools to generate and update schema. You can also use tools for reverse engineering mappings from already available database and to convert 格式之间的映射
创建完整的数据库模式映射请注意,Symfony 应用程序中的 Doctrine 命令名称与 Doctrine 原生提供的名称不同。您需要使用:
doctrine:schema:validate
用于架构验证doctrine:schema:create
用于初始模式生成,随后根据您的需要使用--dump-sql
或--force
调用doctrine:schema:update
doctrine:mapping:convert
对可用数据库进行逆向工程(使用--from-database
选项)或在需要时在映射类型之间进行转换。