繁体   English   中英

Doctrine 不会为新实体生成迁移

[英]Doctrine won't generate migration for new entity

美好的一天,我创建了新实体:

    <?php
    
    namespace Inveocz\CMS\Entity;
    
    class BannerCategory implements BannerCategoryInterface
    {
        
        /** @var int|null */
        protected $id;
    
        /** @return int|null */
        public function getId(): ?int
        {
            return $this->id;
        }
    }

和 xml 映射:

<?xml version="1.0" encoding="UTF-8"?>

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xmlns:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                                      http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

    <mapped-superclass name="Inveocz\CMS\Entity\BannerCategory" table="inveocz_cms_banner_category">
        <id name="id" column="id" type="integer">
            <generator strategy="AUTO"/>
        </id>
    </mapped-superclass>
</doctrine-mapping>

存在问题,doctrine 已注册此新实体,但正在运行

    doctrine:migration:diff

不会在我的项目中生成任何新的迁移。 在此之前为任何其他实体生成它都很好。 当我跑步时:

    doctrine:schema:validate

架构和映射都是有效的。 与:

    doctrine:mapping:info

会告诉我我的“Inveocz\CMS\Entity\BannerCategory”是由 doctrine 注册的。

Symfony:4.4.18

PHP:7.4.9

doctrine.yaml:

    doctrine:
        dbal:
            driver: 'pdo_mysql'
            server_version: '5.7'
            charset: UTF8
    
            url: '%env(resolve:DATABASE_URL)%'
        orm:
            auto_generate_proxy_classes: '%kernel.debug%'
            auto_mapping: true
            mappings:
                App:
                    is_bundle: false
                    type: xml
                    dir: '%kernel.project_dir%/src/Resources/config/doctrine/model'
                    prefix: 'App\Entity'
                    alias: App
    
            dql:
                datetime_functions:
                    date: DoctrineExtensions\Query\Mysql\Date
                    month: DoctrineExtensions\Query\Mysql\Month
                    year: DoctrineExtensions\Query\Mysql\Year
                numeric_functions:
                    round: DoctrineExtensions\Query\Mysql\Round

跑步:

    doctrine:cache:clear-metadata

不会有帮助,丢弃我的 docker 容器也无济于事。 谁能给我暗示什么可能是错的? 非常感谢您的帮助

您的 XML map 您的实体作为映射的超类 这不是数据库中真正存在的实体,只能由其他人继承

使用此 XML 映射到可以从 DB 中持久化和检索的 map 实体:

<doctrine-mapping>
  <entity name="Inveocz\CMS\Entity\BannerCategory" table="inveocz_cms_banner_category">
     <id name="id" column="id" type="integer">
         <generator strategy="AUTO"/>
     </id>
  </entity>
</doctrine-mapping>

资料来源: https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/inheritance-mapping.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM