gpt4 book ai didi

php - 从现有表自动生成 Doctrine-Entity

转载 作者:行者123 更新时间:2023-11-29 01:53:35 25 4
gpt4 key购买 nike

我正在尝试从我数据库的特定表 自动生成实体。我不想在整个数据库中发送 Doctrine ,因为其中有些表与 Doctrine 不兼容(例如遗留数据库中没有主键的表 [是...])。

不幸的是,所有的博客文章和 SO-Anwers 都没有帮助,因为参数“--filter”没有按预期工作。

我做了什么:

我尝试了这个 SO-Answer 的第一步并阅读此 blog post .

php app/console doctrine:mapping:convert metadata_format \
./src/App/UserBundle/Resources/config/doctrine \
--from-database \
--filter="user"

我将过滤器参数理解为仅针对特定表进行过滤的解决方案。但是没有应用此过滤器。该过程被异常取消“表 XYZ 没有主键”(这里是真的,不是问题的一部分)。

我想我可以创建一个完整的新数据库,而无需用于创建注释和实体的有问题的表。但我想知道关于这个过程的内容以及为什么它不起作用。

更新

我也尝试了第一个答案的建议:

php app/console doctrine:mapping:import --force AcmeBlogBundle yml

AcmeBlogBu​​ndle 是我真正的包的占位符。然后导入任务停止:

[Symfony\Component\Debug\Exception\ContextErrorException]
警告:class_parents():类操作不存在且无法加载

第一个表称为“action”。当我删除这张表时,它会在下一张表中停止并出现类似异常。

更新 2

上面提到的一些异常是由于以前使用的 ORM 实现在每个表的名为“实体”的目录中具有类似“ActionEntity.php”的类而引起的。这就是我认为异常发生的原因。在我删除此目录后,异常消失了(但在我的情况下这不是一个好的解决方案)。

我现在做了什么:我删除了所有外键(它们制造了麻烦),我设置了一个全新的 symfony 项目,然后我运行了第一个答案中的所有这些评论,然后我得到了预生成的实体类,但是没有任何外键实现。我现在必须添加的那些东西,包括对数据库方案的一些更改,因为 doctrine 2 在这里有一些限制,比如不支持主键作为外键等等。但现在我可以选择那些实体类并调整与其他实体的缺失连接。

总而言之:整个过程不是很满意......

最佳答案

来自文档:

As the Doctrine tools documentation says, reverse engineering is a one-time process to get started on a project. Doctrine is able to convert approximately 70-80% of the necessary mapping information based on fields, indexes and foreign key constraints. Doctrine can't discover inverse associations, inheritance types, entities with foreign keys as primary keys or semantical operations on associations such as cascade or lifecycle events. Some additional work on the generated entities will be necessary afterwards to design each to fit your domain model specificities.

从数据库导入实体的正确步骤:

  1. php bin/console doctrine:mapping:import --force AcmeBlogBu​​ndle xml
  2. php bin/console doctrine:mapping:convert annotation ./src
  3. php bin/console doctrine:generate:entities AcmeBlogBu​​ndle

您可以使用 xmlyml,但对于我的情况,它仅适用于 xml

关于php - 从现有表自动生成 Doctrine-Entity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34830718/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com