Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

symfony - Doctrine won't generate migration for new entity

Good day, I have created new entity:

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

and xml mapping for it:

<?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="InveoczCMSEntityBannerCategory" table="inveocz_cms_banner_category">
        <id name="id" column="id" type="integer">
            <generator strategy="AUTO"/>
        </id>
    </mapped-superclass>
</doctrine-mapping>

There is issues, that doctrine have registered this new entity, but running

    doctrine:migration:diff

won't generate any new migration in my project. Before that generating it for any other entity was fine. Also when I run:

    doctrine:schema:validate

both schema and mapping are valid. Same with:

    doctrine:mapping:info

will tell me that my "InveoczCMSEntityBannerCategory" is registered by 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: 'AppEntity'
                    alias: App
    
            dql:
                datetime_functions:
                    date: DoctrineExtensionsQueryMysqlDate
                    month: DoctrineExtensionsQueryMysqlMonth
                    year: DoctrineExtensionsQueryMysqlYear
                numeric_functions:
                    round: DoctrineExtensionsQueryMysqlRound

Running:

    doctrine:cache:clear-metadata

won't help and droping my docker containers won't help either. Can anyone give me hint what could possibly be wrong? Thank much for any help

question from:https://stackoverflow.com/questions/65830568/doctrine-wont-generate-migration-for-new-entity

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your XML map your entity as mapped superclass. This is not entity that really exists in database and can be only inherited by others.

Use this XML mapping to map entity that can be persisted and retrieved from DB:

<doctrine-mapping>
  <entity name="InveoczCMSEntityBannerCategory" table="inveocz_cms_banner_category">
     <id name="id" column="id" type="integer">
         <generator strategy="AUTO"/>
     </id>
  </entity>
</doctrine-mapping>

Source: https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/inheritance-mapping.html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...