Php Symfony3-多实体管理器和连接
我尝试从预先存在的数据库中的表创建实体:Php Symfony3-多实体管理器和连接,php,doctrine-orm,symfony,Php,Doctrine Orm,Symfony,我尝试从预先存在的数据库中的表创建实体: php bin/console doctrine:mapping:import --force AppBundle yml --filter="someTable" 但一条信息显示: 表someTable没有主键。教义不支持反向 从没有主键的表进行工程 我检查了,在DB中,有一些表没有任何PK(我无法更改)。 所以我读了这一页: ... 并在github上尝试了此解决方案: 我的config.yml如下所示: doctrine: dbal:
php bin/console doctrine:mapping:import --force AppBundle yml --filter="someTable"
但一条信息显示:
表someTable没有主键。教义不支持反向
从没有主键的表进行工程
我检查了,在DB中,有一些表没有任何PK(我无法更改)。
所以我读了这一页:
... 并在github上尝试了此解决方案:
我的config.yml如下所示:
doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
mapping_types:
enum: string
forMapping:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
schema_filter: someTable
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
default_entity_manager: default
entity_managers:
default:
connection: default
mappings:
AppBundle:
type: yml
dir: Resources/config
forMapping:
connection: forMapping
mappings:
AppBundle:
type: yml
dir: Resources/config
但当我尝试时:
php bin/console doctrine:mapping:import --em=forMapping --filter="someTable" AppBundle yml
我得到:
[InvalidArgumentException]名为“FormMapping”的条令ORM管理器不存在
清空了缓存,但没有。谢谢你的帮助
对不起,我刚才的回答搞错了。 不如试试这样的命令:
php bin/console doctrine:mapping:import "AppBundle" yml --em=forMapping --filter="someTable"
这有区别吗?我使用--help从命令行中看到,它是按顺序显示的。对不起,我之前的回答搞错了。 不如试试这样的命令:
php bin/console doctrine:mapping:import "AppBundle" yml --em=forMapping --filter="someTable"
这有区别吗?我从使用--help的命令行中看到,它按顺序显示。看起来您的“格式映射”在中不正确
orm:
entity_managers:
#problem here
forMapping:
试着找出这里出了什么问题看起来您的“格式映射”在中是不正确的
orm:
entity_managers:
#problem here
forMapping:
试着找出这里出了什么问题[Solved]是由于“自动映射”造成的。正确的顺序似乎是:
orm:
default_entity_manager: default
entity_managers:
auto_mapping: true
default:
connection: default
mappings:
AppBundle:
type: yml
dir: Resources/config
# See https://github.com/doctrine/DoctrineBundle/issues/441
forMapping:
connection: forMapping
mappings:
AppBundle:
type: yml
dir: Resources/config
它会进一步工作到下一个错误消息。当我尝试时:
php bin/console原则:映射:导入“AppBundle”yml--em=forMapping
弹出以下错误消息:
[Symfony\Component\Debug\Exception\ContextErrorException]警告:preg_match():分隔符不能是字母数字或反斜杠 好的,让我们看看这个。架构过滤器错误。正确的代码是:
schema_filter: ~^spip_rubriques$~
我的实体已正确生成。谢谢大家的帮助
MC[Solved]是由于“自动映射”。正确的顺序似乎是:
orm:
default_entity_manager: default
entity_managers:
auto_mapping: true
default:
connection: default
mappings:
AppBundle:
type: yml
dir: Resources/config
# See https://github.com/doctrine/DoctrineBundle/issues/441
forMapping:
connection: forMapping
mappings:
AppBundle:
type: yml
dir: Resources/config
它会进一步工作到下一个错误消息。当我尝试时:
php bin/console原则:映射:导入“AppBundle”yml--em=forMapping
弹出以下错误消息:
[Symfony\Component\Debug\Exception\ContextErrorException]警告:preg_match():分隔符不能是字母数字或反斜杠 好的,让我们看看这个。架构过滤器错误。正确的代码是:
schema_filter: ~^spip_rubriques$~
我的实体已正确生成。谢谢大家的帮助
MC有趣的建议。假设实体是使用import命令生成的,并且import命令没有运行,那么您将如何准确地检查这些不存在的实体?为什么在使用yaml映射选项时会有注释呢?我刚刚意识到我搞错了。谢谢你的提示@Cerad!有趣的建议。假设实体是使用import命令生成的,并且import命令没有运行,那么您将如何准确地检查这些不存在的实体?为什么在使用yaml映射选项时会有注释呢?我刚刚意识到我搞错了。谢谢你的提示@Cerad!移除自动映射行。移除自动映射行。那么
原则:映射:导入
选项的顺序是否重要?你能在我的答案上点击上三角表示我(以某种方式)提供了帮助吗?所以原则:映射:导入
选项的顺序很重要?你能在我的答案上点击上三角表示我有帮助吗?