# How to add definition, entity classes for new fields in existing tables?

**URL:** <https://forum.shopware.com/t/how-to-add-definition-entity-classes-for-new-fields-in-existing-tables/65124>\
**Category:** General Questions (EN)\
**Created:** [2. März 2020 um 11:14 UTC](https://forum.shopware.com/t/how-to-add-definition-entity-classes-for-new-fields-in-existing-tables/65124 "2020-03-02T11:14:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![abinjohnedamana](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/abinjohnedamana/32/17378_2.png) [@abinjohnedamana](https://forum.shopware.com/u/abinjohnedamana)\
**Post date:** [2. März 2020 um 11:14 UTC](https://forum.shopware.com/t/how-to-add-definition-entity-classes-for-new-fields-in-existing-tables/65124/1 "2020-03-02T11:14:57Z")

</div>

Hi

I have to add two more fields published\_from, published\_to in `cms_page` table.

I have created a migration file. The migration is working fine.

Then i need to create the definition file right?

\<?php declare(strict\_types=1);

namespace Hatslogic\Sw\ProductsAndLayoutsScheduler\Core\Content\Cms; use Shopware\Core\Content\Cms\CmsPageDefinition; use Shopware\Core\Framework\DataAbstractionLayer\EntityExtensionInterface; use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Inherited; use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection; use Shopware\Core\Framework\DataAbstractionLayer\Field\DateTimeField; class CmsPageExtension implements EntityExtensionInterface { &nbsp; &nbsp; public function extendFields(FieldCollection $collection): void &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; $collection-\\>add( &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (new DateTimeField('published\_from', 'publishedFrom')), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (new DateTimeField('published\_to', 'publishedTo')) &nbsp; &nbsp; &nbsp; &nbsp; ); &nbsp; &nbsp; } &nbsp; &nbsp; public function getDefinitionClass(): string &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; return CmsPageDefinition::class; &nbsp; &nbsp; } } But i am getting the following error "Only AssociationFields, FkFields/ReferenceVersionFields for a ManyToOneAssociationField or fields flagged as Runtime can be added as Extension." How to add definition, entity classes for new fields in existing tables?

---

<div class="post-metadata">

**Author:** ![abinjohnedamana](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/abinjohnedamana/32/17378_2.png) [@abinjohnedamana](https://forum.shopware.com/u/abinjohnedamana)\
**Post date:** [5. März 2020 um 07:54 UTC](https://forum.shopware.com/t/how-to-add-definition-entity-classes-for-new-fields-in-existing-tables/65124/2 "2020-03-05T07:54:53Z")

</div>

Entity extensions are not meant to be used for scalar extensions. for that, there are the custom fields.  
you could only use associations or foreign keys

most entities have the custom fields column in the database. but not all modules in the admin does have a UI for that. so it is possible to create new custom fields with your plugin. but sometimes you need to extend a module to show them to the admin user

---

<div class="post-metadata">

**Author:** ![abinjohnedamana](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/abinjohnedamana/32/17378_2.png) [@abinjohnedamana](https://forum.shopware.com/u/abinjohnedamana)\
**Post date:** [5. März 2020 um 07:56 UTC](https://forum.shopware.com/t/how-to-add-definition-entity-classes-for-new-fields-in-existing-tables/65124/3 "2020-03-05T07:56:38Z")

</div>

```
import { Component } from 'src/core/shopware';
import template from './sw-cms-sidebar.html.twig';
const { Criteria } = Shopware.Data;

Component.override('sw-cms-sidebar', {
    template,

    data() {
        return {
            customFieldSets: [],
            isLoading: false
        };
    },

    computed: {
    	customFieldSetRepository() {
            return this.repositoryFactory.create('custom_field_set');
        },

        customFieldSetCriteria() {
            const criteria = new Criteria();
            criteria.setPage(1);
            criteria.setLimit(100);
            criteria.addFilter(
                Criteria.equals('relations.entityName', 'cms_page')
            );

            criteria.getAssociation('customFields')
                .addSorting(Criteria.sort('config.customFieldPosition', 'ASC'))
                .setLimit(100);

            return criteria;
        },
    },

    created() {
        this.loadEntityData();
    },

    methods: {
        loadEntityData() {
            this.isLoading = true;

            this.customFieldSetRepository
                .search(this.customFieldSetCriteria, Shopware.Context.api)
                .then((result) => {
                	this.isLoading = false;
                    this.customFieldSets = result.filter((set) => set.customFields.length > 0);
                });
        }
    }
});

{% block sw_cms_sidebar_page_settings_type_field %}

{% parent %}
    
          
          
    
{% endblock %}

```

I have displayed the custom fields in admin side using the above code.
