Magento 2.3 - How to add custom column to customer_entity table












1















I'm creating a Referral Program module, and I want to create a custom column inside the customer_entity table. The column is referred_by and it's a foreign key that as a relation with the customer_entity table itself. This column contains the id of the customer that sent the referral_code. How can I implement this? How can I add this field inside the customer_entity table? I try to add an attribute as static type, but the new column doesn't appear inside that table. I need to declere the db_schema.xml?










share|improve this question







New contributor




Mirko Rapisarda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    1















    I'm creating a Referral Program module, and I want to create a custom column inside the customer_entity table. The column is referred_by and it's a foreign key that as a relation with the customer_entity table itself. This column contains the id of the customer that sent the referral_code. How can I implement this? How can I add this field inside the customer_entity table? I try to add an attribute as static type, but the new column doesn't appear inside that table. I need to declere the db_schema.xml?










    share|improve this question







    New contributor




    Mirko Rapisarda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      1












      1








      1








      I'm creating a Referral Program module, and I want to create a custom column inside the customer_entity table. The column is referred_by and it's a foreign key that as a relation with the customer_entity table itself. This column contains the id of the customer that sent the referral_code. How can I implement this? How can I add this field inside the customer_entity table? I try to add an attribute as static type, but the new column doesn't appear inside that table. I need to declere the db_schema.xml?










      share|improve this question







      New contributor




      Mirko Rapisarda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      I'm creating a Referral Program module, and I want to create a custom column inside the customer_entity table. The column is referred_by and it's a foreign key that as a relation with the customer_entity table itself. This column contains the id of the customer that sent the referral_code. How can I implement this? How can I add this field inside the customer_entity table? I try to add an attribute as static type, but the new column doesn't appear inside that table. I need to declere the db_schema.xml?







      customer-attribute declarative-schema






      share|improve this question







      New contributor




      Mirko Rapisarda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      Mirko Rapisarda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      Mirko Rapisarda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked yesterday









      Mirko RapisardaMirko Rapisarda

      336




      336




      New contributor




      Mirko Rapisarda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Mirko Rapisarda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Mirko Rapisarda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          3 Answers
          3






          active

          oldest

          votes


















          3














          You can try using following code.



          app/code/Anshu/CustomerEdit/registration.php



          <?php

          use MagentoFrameworkComponentComponentRegistrar;

          ComponentRegistrar::register(
          ComponentRegistrar::MODULE,
          'Anshu_CustomerEdit',
          __DIR__
          );


          app/code/Anshu/CustomerEdit/etc/module.xml



          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
          <module name="Anshu_CustomerEdit" >
          <sequence>
          <module name="Magento_Customer"/>
          </sequence>
          </module>
          </config>


          app/code/Anshu/CustomerEdit/etc/db_schema.xml



          <?xml version="1.0"?>
          <schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
          <table name="customer_entity">
          <column xsi:type="int" name="referred_by" padding="10" unsigned="true" nullable="false"
          comment="Referred By"/>
          <constraint xsi:type="foreign" referenceId="CUSTOMER_ENTITY_REFERRED_BY_CUSTOMER_ENTITY_ENTITY_ID" table="customer_entity"
          column="referred_by" referenceTable="customer_entity" referenceColumn="entity_id" onDelete="CASCADE"/>
          </table>
          </schema>


          Then run following command to generate db_schema_whitelist.json



          bin/magento setup:db-declaration:generate-whitelist


          Then run bin/magento setup:upgrade command.



          Here Anshu is the module namespace and CustomerEdit is the module name.



          You can modify code according to your requirement.






          share|improve this answer
























          • How do you set value to this field @AnushuMishra

            – Prathap Gunasekaran
            yesterday











          • @PrathapGunasekaran This will just add the field in the table. To add the content in the field Data Patch needs to be created. You can read about them at devdocs.magento.com/guides/v2.3/extension-dev-guide/…

            – Anshu Mishra
            yesterday



















          0














          You can use InstallSchema Script to do that. Kindly refer below code:



          <?php

          namespace vendormoduleSetup;

          use MagentoFrameworkSetupInstallSchemaInterface;
          use MagentoFrameworkSetupModuleContextInterface;
          use MagentoFrameworkSetupSchemaSetupInterface;
          use MagentoFrameworkDBDdlTable;

          class InstallSchema implements InstallSchemaInterface
          {
          /**
          * {@inheritdoc}
          */
          public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
          {
          $setup->startSetup();

          $table = $setup->getConnection()->newTable(
          $setup->getTable('customer_entity')
          )->addColumn(
          'referred_by',
          MagentoFrameworkDBDdlTable::TYPE_INTEGER,
          255,
          ['identity' => true, 'nullable' => true],
          'Referred By'
          )->setComment("Id of the customer that sent the Referral code");

          $setup->getConnection()->createTable($table);

          $setup->endSetup();
          }
          }





          share|improve this answer
























          • ok, and then how can I add the field inside the entity model of customer? Because this field then I need to get and set

            – Mirko Rapisarda
            yesterday








          • 1





            @magefms M2.3 should be added via declarative schema even though it acepts, correct me if am wrong

            – Prathap Gunasekaran
            yesterday











          • @MirkoRapisarda Try with customer attribute for your requirement you can't do this via custom field in a table.

            – Prathap Gunasekaran
            yesterday











          • @PrathapGunasekaran, yeah you are right but just giving him an easier way for now since it also works for 2.3.

            – magefms
            yesterday






          • 1





            @PrathapGunasekaran but with custom attribute, I lost the possibility to add a foreign key relationship, for this reason I want to add it as a real column

            – Mirko Rapisarda
            yesterday



















          0














          Create new customer custom attribute for referral_code while installing referral module. here is a link to follow how to add custom attribute in customer section.



          https://www.mageplaza.com/magento-2-module-development/magento-2-add-customer-attribute-programmatically.html



          you can fetch custom attribute value from customer object using below code.



          $customer->getCustomAttribute('FIELD_NAME')->getValue();


          replace FIELD_NAME by your custom attribute name






          share|improve this answer
























          • but in this way I lost the possibility to add the referenced_by field as a foreign key

            – Mirko Rapisarda
            yesterday











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "479"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          Mirko Rapisarda is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f266635%2fmagento-2-3-how-to-add-custom-column-to-customer-entity-table%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          3 Answers
          3






          active

          oldest

          votes








          3 Answers
          3






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          You can try using following code.



          app/code/Anshu/CustomerEdit/registration.php



          <?php

          use MagentoFrameworkComponentComponentRegistrar;

          ComponentRegistrar::register(
          ComponentRegistrar::MODULE,
          'Anshu_CustomerEdit',
          __DIR__
          );


          app/code/Anshu/CustomerEdit/etc/module.xml



          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
          <module name="Anshu_CustomerEdit" >
          <sequence>
          <module name="Magento_Customer"/>
          </sequence>
          </module>
          </config>


          app/code/Anshu/CustomerEdit/etc/db_schema.xml



          <?xml version="1.0"?>
          <schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
          <table name="customer_entity">
          <column xsi:type="int" name="referred_by" padding="10" unsigned="true" nullable="false"
          comment="Referred By"/>
          <constraint xsi:type="foreign" referenceId="CUSTOMER_ENTITY_REFERRED_BY_CUSTOMER_ENTITY_ENTITY_ID" table="customer_entity"
          column="referred_by" referenceTable="customer_entity" referenceColumn="entity_id" onDelete="CASCADE"/>
          </table>
          </schema>


          Then run following command to generate db_schema_whitelist.json



          bin/magento setup:db-declaration:generate-whitelist


          Then run bin/magento setup:upgrade command.



          Here Anshu is the module namespace and CustomerEdit is the module name.



          You can modify code according to your requirement.






          share|improve this answer
























          • How do you set value to this field @AnushuMishra

            – Prathap Gunasekaran
            yesterday











          • @PrathapGunasekaran This will just add the field in the table. To add the content in the field Data Patch needs to be created. You can read about them at devdocs.magento.com/guides/v2.3/extension-dev-guide/…

            – Anshu Mishra
            yesterday
















          3














          You can try using following code.



          app/code/Anshu/CustomerEdit/registration.php



          <?php

          use MagentoFrameworkComponentComponentRegistrar;

          ComponentRegistrar::register(
          ComponentRegistrar::MODULE,
          'Anshu_CustomerEdit',
          __DIR__
          );


          app/code/Anshu/CustomerEdit/etc/module.xml



          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
          <module name="Anshu_CustomerEdit" >
          <sequence>
          <module name="Magento_Customer"/>
          </sequence>
          </module>
          </config>


          app/code/Anshu/CustomerEdit/etc/db_schema.xml



          <?xml version="1.0"?>
          <schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
          <table name="customer_entity">
          <column xsi:type="int" name="referred_by" padding="10" unsigned="true" nullable="false"
          comment="Referred By"/>
          <constraint xsi:type="foreign" referenceId="CUSTOMER_ENTITY_REFERRED_BY_CUSTOMER_ENTITY_ENTITY_ID" table="customer_entity"
          column="referred_by" referenceTable="customer_entity" referenceColumn="entity_id" onDelete="CASCADE"/>
          </table>
          </schema>


          Then run following command to generate db_schema_whitelist.json



          bin/magento setup:db-declaration:generate-whitelist


          Then run bin/magento setup:upgrade command.



          Here Anshu is the module namespace and CustomerEdit is the module name.



          You can modify code according to your requirement.






          share|improve this answer
























          • How do you set value to this field @AnushuMishra

            – Prathap Gunasekaran
            yesterday











          • @PrathapGunasekaran This will just add the field in the table. To add the content in the field Data Patch needs to be created. You can read about them at devdocs.magento.com/guides/v2.3/extension-dev-guide/…

            – Anshu Mishra
            yesterday














          3












          3








          3







          You can try using following code.



          app/code/Anshu/CustomerEdit/registration.php



          <?php

          use MagentoFrameworkComponentComponentRegistrar;

          ComponentRegistrar::register(
          ComponentRegistrar::MODULE,
          'Anshu_CustomerEdit',
          __DIR__
          );


          app/code/Anshu/CustomerEdit/etc/module.xml



          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
          <module name="Anshu_CustomerEdit" >
          <sequence>
          <module name="Magento_Customer"/>
          </sequence>
          </module>
          </config>


          app/code/Anshu/CustomerEdit/etc/db_schema.xml



          <?xml version="1.0"?>
          <schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
          <table name="customer_entity">
          <column xsi:type="int" name="referred_by" padding="10" unsigned="true" nullable="false"
          comment="Referred By"/>
          <constraint xsi:type="foreign" referenceId="CUSTOMER_ENTITY_REFERRED_BY_CUSTOMER_ENTITY_ENTITY_ID" table="customer_entity"
          column="referred_by" referenceTable="customer_entity" referenceColumn="entity_id" onDelete="CASCADE"/>
          </table>
          </schema>


          Then run following command to generate db_schema_whitelist.json



          bin/magento setup:db-declaration:generate-whitelist


          Then run bin/magento setup:upgrade command.



          Here Anshu is the module namespace and CustomerEdit is the module name.



          You can modify code according to your requirement.






          share|improve this answer













          You can try using following code.



          app/code/Anshu/CustomerEdit/registration.php



          <?php

          use MagentoFrameworkComponentComponentRegistrar;

          ComponentRegistrar::register(
          ComponentRegistrar::MODULE,
          'Anshu_CustomerEdit',
          __DIR__
          );


          app/code/Anshu/CustomerEdit/etc/module.xml



          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
          <module name="Anshu_CustomerEdit" >
          <sequence>
          <module name="Magento_Customer"/>
          </sequence>
          </module>
          </config>


          app/code/Anshu/CustomerEdit/etc/db_schema.xml



          <?xml version="1.0"?>
          <schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
          <table name="customer_entity">
          <column xsi:type="int" name="referred_by" padding="10" unsigned="true" nullable="false"
          comment="Referred By"/>
          <constraint xsi:type="foreign" referenceId="CUSTOMER_ENTITY_REFERRED_BY_CUSTOMER_ENTITY_ENTITY_ID" table="customer_entity"
          column="referred_by" referenceTable="customer_entity" referenceColumn="entity_id" onDelete="CASCADE"/>
          </table>
          </schema>


          Then run following command to generate db_schema_whitelist.json



          bin/magento setup:db-declaration:generate-whitelist


          Then run bin/magento setup:upgrade command.



          Here Anshu is the module namespace and CustomerEdit is the module name.



          You can modify code according to your requirement.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered yesterday









          Anshu MishraAnshu Mishra

          5,51652660




          5,51652660













          • How do you set value to this field @AnushuMishra

            – Prathap Gunasekaran
            yesterday











          • @PrathapGunasekaran This will just add the field in the table. To add the content in the field Data Patch needs to be created. You can read about them at devdocs.magento.com/guides/v2.3/extension-dev-guide/…

            – Anshu Mishra
            yesterday



















          • How do you set value to this field @AnushuMishra

            – Prathap Gunasekaran
            yesterday











          • @PrathapGunasekaran This will just add the field in the table. To add the content in the field Data Patch needs to be created. You can read about them at devdocs.magento.com/guides/v2.3/extension-dev-guide/…

            – Anshu Mishra
            yesterday

















          How do you set value to this field @AnushuMishra

          – Prathap Gunasekaran
          yesterday





          How do you set value to this field @AnushuMishra

          – Prathap Gunasekaran
          yesterday













          @PrathapGunasekaran This will just add the field in the table. To add the content in the field Data Patch needs to be created. You can read about them at devdocs.magento.com/guides/v2.3/extension-dev-guide/…

          – Anshu Mishra
          yesterday





          @PrathapGunasekaran This will just add the field in the table. To add the content in the field Data Patch needs to be created. You can read about them at devdocs.magento.com/guides/v2.3/extension-dev-guide/…

          – Anshu Mishra
          yesterday













          0














          You can use InstallSchema Script to do that. Kindly refer below code:



          <?php

          namespace vendormoduleSetup;

          use MagentoFrameworkSetupInstallSchemaInterface;
          use MagentoFrameworkSetupModuleContextInterface;
          use MagentoFrameworkSetupSchemaSetupInterface;
          use MagentoFrameworkDBDdlTable;

          class InstallSchema implements InstallSchemaInterface
          {
          /**
          * {@inheritdoc}
          */
          public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
          {
          $setup->startSetup();

          $table = $setup->getConnection()->newTable(
          $setup->getTable('customer_entity')
          )->addColumn(
          'referred_by',
          MagentoFrameworkDBDdlTable::TYPE_INTEGER,
          255,
          ['identity' => true, 'nullable' => true],
          'Referred By'
          )->setComment("Id of the customer that sent the Referral code");

          $setup->getConnection()->createTable($table);

          $setup->endSetup();
          }
          }





          share|improve this answer
























          • ok, and then how can I add the field inside the entity model of customer? Because this field then I need to get and set

            – Mirko Rapisarda
            yesterday








          • 1





            @magefms M2.3 should be added via declarative schema even though it acepts, correct me if am wrong

            – Prathap Gunasekaran
            yesterday











          • @MirkoRapisarda Try with customer attribute for your requirement you can't do this via custom field in a table.

            – Prathap Gunasekaran
            yesterday











          • @PrathapGunasekaran, yeah you are right but just giving him an easier way for now since it also works for 2.3.

            – magefms
            yesterday






          • 1





            @PrathapGunasekaran but with custom attribute, I lost the possibility to add a foreign key relationship, for this reason I want to add it as a real column

            – Mirko Rapisarda
            yesterday
















          0














          You can use InstallSchema Script to do that. Kindly refer below code:



          <?php

          namespace vendormoduleSetup;

          use MagentoFrameworkSetupInstallSchemaInterface;
          use MagentoFrameworkSetupModuleContextInterface;
          use MagentoFrameworkSetupSchemaSetupInterface;
          use MagentoFrameworkDBDdlTable;

          class InstallSchema implements InstallSchemaInterface
          {
          /**
          * {@inheritdoc}
          */
          public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
          {
          $setup->startSetup();

          $table = $setup->getConnection()->newTable(
          $setup->getTable('customer_entity')
          )->addColumn(
          'referred_by',
          MagentoFrameworkDBDdlTable::TYPE_INTEGER,
          255,
          ['identity' => true, 'nullable' => true],
          'Referred By'
          )->setComment("Id of the customer that sent the Referral code");

          $setup->getConnection()->createTable($table);

          $setup->endSetup();
          }
          }





          share|improve this answer
























          • ok, and then how can I add the field inside the entity model of customer? Because this field then I need to get and set

            – Mirko Rapisarda
            yesterday








          • 1





            @magefms M2.3 should be added via declarative schema even though it acepts, correct me if am wrong

            – Prathap Gunasekaran
            yesterday











          • @MirkoRapisarda Try with customer attribute for your requirement you can't do this via custom field in a table.

            – Prathap Gunasekaran
            yesterday











          • @PrathapGunasekaran, yeah you are right but just giving him an easier way for now since it also works for 2.3.

            – magefms
            yesterday






          • 1





            @PrathapGunasekaran but with custom attribute, I lost the possibility to add a foreign key relationship, for this reason I want to add it as a real column

            – Mirko Rapisarda
            yesterday














          0












          0








          0







          You can use InstallSchema Script to do that. Kindly refer below code:



          <?php

          namespace vendormoduleSetup;

          use MagentoFrameworkSetupInstallSchemaInterface;
          use MagentoFrameworkSetupModuleContextInterface;
          use MagentoFrameworkSetupSchemaSetupInterface;
          use MagentoFrameworkDBDdlTable;

          class InstallSchema implements InstallSchemaInterface
          {
          /**
          * {@inheritdoc}
          */
          public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
          {
          $setup->startSetup();

          $table = $setup->getConnection()->newTable(
          $setup->getTable('customer_entity')
          )->addColumn(
          'referred_by',
          MagentoFrameworkDBDdlTable::TYPE_INTEGER,
          255,
          ['identity' => true, 'nullable' => true],
          'Referred By'
          )->setComment("Id of the customer that sent the Referral code");

          $setup->getConnection()->createTable($table);

          $setup->endSetup();
          }
          }





          share|improve this answer













          You can use InstallSchema Script to do that. Kindly refer below code:



          <?php

          namespace vendormoduleSetup;

          use MagentoFrameworkSetupInstallSchemaInterface;
          use MagentoFrameworkSetupModuleContextInterface;
          use MagentoFrameworkSetupSchemaSetupInterface;
          use MagentoFrameworkDBDdlTable;

          class InstallSchema implements InstallSchemaInterface
          {
          /**
          * {@inheritdoc}
          */
          public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
          {
          $setup->startSetup();

          $table = $setup->getConnection()->newTable(
          $setup->getTable('customer_entity')
          )->addColumn(
          'referred_by',
          MagentoFrameworkDBDdlTable::TYPE_INTEGER,
          255,
          ['identity' => true, 'nullable' => true],
          'Referred By'
          )->setComment("Id of the customer that sent the Referral code");

          $setup->getConnection()->createTable($table);

          $setup->endSetup();
          }
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered yesterday









          magefmsmagefms

          1,9271425




          1,9271425













          • ok, and then how can I add the field inside the entity model of customer? Because this field then I need to get and set

            – Mirko Rapisarda
            yesterday








          • 1





            @magefms M2.3 should be added via declarative schema even though it acepts, correct me if am wrong

            – Prathap Gunasekaran
            yesterday











          • @MirkoRapisarda Try with customer attribute for your requirement you can't do this via custom field in a table.

            – Prathap Gunasekaran
            yesterday











          • @PrathapGunasekaran, yeah you are right but just giving him an easier way for now since it also works for 2.3.

            – magefms
            yesterday






          • 1





            @PrathapGunasekaran but with custom attribute, I lost the possibility to add a foreign key relationship, for this reason I want to add it as a real column

            – Mirko Rapisarda
            yesterday



















          • ok, and then how can I add the field inside the entity model of customer? Because this field then I need to get and set

            – Mirko Rapisarda
            yesterday








          • 1





            @magefms M2.3 should be added via declarative schema even though it acepts, correct me if am wrong

            – Prathap Gunasekaran
            yesterday











          • @MirkoRapisarda Try with customer attribute for your requirement you can't do this via custom field in a table.

            – Prathap Gunasekaran
            yesterday











          • @PrathapGunasekaran, yeah you are right but just giving him an easier way for now since it also works for 2.3.

            – magefms
            yesterday






          • 1





            @PrathapGunasekaran but with custom attribute, I lost the possibility to add a foreign key relationship, for this reason I want to add it as a real column

            – Mirko Rapisarda
            yesterday

















          ok, and then how can I add the field inside the entity model of customer? Because this field then I need to get and set

          – Mirko Rapisarda
          yesterday







          ok, and then how can I add the field inside the entity model of customer? Because this field then I need to get and set

          – Mirko Rapisarda
          yesterday






          1




          1





          @magefms M2.3 should be added via declarative schema even though it acepts, correct me if am wrong

          – Prathap Gunasekaran
          yesterday





          @magefms M2.3 should be added via declarative schema even though it acepts, correct me if am wrong

          – Prathap Gunasekaran
          yesterday













          @MirkoRapisarda Try with customer attribute for your requirement you can't do this via custom field in a table.

          – Prathap Gunasekaran
          yesterday





          @MirkoRapisarda Try with customer attribute for your requirement you can't do this via custom field in a table.

          – Prathap Gunasekaran
          yesterday













          @PrathapGunasekaran, yeah you are right but just giving him an easier way for now since it also works for 2.3.

          – magefms
          yesterday





          @PrathapGunasekaran, yeah you are right but just giving him an easier way for now since it also works for 2.3.

          – magefms
          yesterday




          1




          1





          @PrathapGunasekaran but with custom attribute, I lost the possibility to add a foreign key relationship, for this reason I want to add it as a real column

          – Mirko Rapisarda
          yesterday





          @PrathapGunasekaran but with custom attribute, I lost the possibility to add a foreign key relationship, for this reason I want to add it as a real column

          – Mirko Rapisarda
          yesterday











          0














          Create new customer custom attribute for referral_code while installing referral module. here is a link to follow how to add custom attribute in customer section.



          https://www.mageplaza.com/magento-2-module-development/magento-2-add-customer-attribute-programmatically.html



          you can fetch custom attribute value from customer object using below code.



          $customer->getCustomAttribute('FIELD_NAME')->getValue();


          replace FIELD_NAME by your custom attribute name






          share|improve this answer
























          • but in this way I lost the possibility to add the referenced_by field as a foreign key

            – Mirko Rapisarda
            yesterday
















          0














          Create new customer custom attribute for referral_code while installing referral module. here is a link to follow how to add custom attribute in customer section.



          https://www.mageplaza.com/magento-2-module-development/magento-2-add-customer-attribute-programmatically.html



          you can fetch custom attribute value from customer object using below code.



          $customer->getCustomAttribute('FIELD_NAME')->getValue();


          replace FIELD_NAME by your custom attribute name






          share|improve this answer
























          • but in this way I lost the possibility to add the referenced_by field as a foreign key

            – Mirko Rapisarda
            yesterday














          0












          0








          0







          Create new customer custom attribute for referral_code while installing referral module. here is a link to follow how to add custom attribute in customer section.



          https://www.mageplaza.com/magento-2-module-development/magento-2-add-customer-attribute-programmatically.html



          you can fetch custom attribute value from customer object using below code.



          $customer->getCustomAttribute('FIELD_NAME')->getValue();


          replace FIELD_NAME by your custom attribute name






          share|improve this answer













          Create new customer custom attribute for referral_code while installing referral module. here is a link to follow how to add custom attribute in customer section.



          https://www.mageplaza.com/magento-2-module-development/magento-2-add-customer-attribute-programmatically.html



          you can fetch custom attribute value from customer object using below code.



          $customer->getCustomAttribute('FIELD_NAME')->getValue();


          replace FIELD_NAME by your custom attribute name







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered yesterday









          Kruti AparnathiKruti Aparnathi

          463




          463













          • but in this way I lost the possibility to add the referenced_by field as a foreign key

            – Mirko Rapisarda
            yesterday



















          • but in this way I lost the possibility to add the referenced_by field as a foreign key

            – Mirko Rapisarda
            yesterday

















          but in this way I lost the possibility to add the referenced_by field as a foreign key

          – Mirko Rapisarda
          yesterday





          but in this way I lost the possibility to add the referenced_by field as a foreign key

          – Mirko Rapisarda
          yesterday










          Mirko Rapisarda is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          Mirko Rapisarda is a new contributor. Be nice, and check out our Code of Conduct.













          Mirko Rapisarda is a new contributor. Be nice, and check out our Code of Conduct.












          Mirko Rapisarda is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f266635%2fmagento-2-3-how-to-add-custom-column-to-customer-entity-table%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          數位音樂下載

          When can things happen in Etherscan, such as the picture below?

          格利澤436b