Insert multiple records to multiple custom tables through install script in magento2 The Next...

Could a dragon use its wings to swim?

Does int main() need a declaration on C++?

Why does the freezing point matter when picking cooler ice packs?

Could you use a laser beam as a modulated carrier wave for radio signal?

"Eavesdropping" vs "Listen in on"

How to show a landlord what we have in savings?

How did scripture get the name bible?

How dangerous is XSS

How to pronounce fünf in 45

Calculating discount not working

How exploitable/balanced is this homebrew spell: Spell Permanency?

Why can't we say "I have been having a dog"?

Shortening a title without changing its meaning

Is it a bad idea to plug the other end of ESD strap to wall ground?

Traveling with my 5 year old daughter (as the father) without the mother from Germany to Mexico

Calculate the Mean mean of two numbers

Compensation for working overtime on Saturdays

Oldie but Goldie

Mathematica command that allows it to read my intentions

Prodigo = pro + ago?

How can the PCs determine if an item is a phylactery?

Can you teleport closer to a creature you are Frightened of?

My boss doesn't want me to have a side project

Why does sin(x) - sin(y) equal this?



Insert multiple records to multiple custom tables through install script in magento2



The Next CEO of Stack OverflowDifference between InstallSchema and InstallDataMagento setup resources not working in magento 1.8.1How to update existing cms page through install scriptMagento2: Setup Script not loadedmain.CRITICAL: Plugin class doesn't existMagento 2: How to Insert Multiple Records to custom table?Magento 2.1: Not add table into databaseMagento 2 Add new field to Magento_User admin formMagento 2 Reindex failed on customer gridI have created an extension to show Customer Company Name in Order grid. But when creating new order, order is not showing in order gridMagento offline custom Payment method with drop down list












0















I have created multiple table schema using setup script like below.



Setup/InstallSchema.php



   namespace VendorModuleSetup;
use MagentoFrameworkSetupInstallSchemaInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupSchemaSetupInterface;

class InstallSchema implements InstallSchemaInterface
{

public function install(SchemaSetupInterface $setup,
ModuleContextInterface $context)
{
/**
* Create table 'tbl_test1'
*/
$table = $setup->getConnection()
->newTable($setup->getTable('tbl_test1'))
->addColumn(
'id',
MagentoFrameworkDBDdlTable::TYPE_INTEGER,
null,
['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
'Pod ID'
)
->addColumn(
'name',
MagentoFrameworkDBDdlTable::TYPE_TEXT,
255,
['nullable' => false, 'default' => ''],
'name'
);
$setup->getConnection()->createTable($table);

/**
* Create table 'tbl_test_2'
*/
$table = $setup->getConnection()
->newTable($setup->getTable('tbl_test_2'))
->addColumn(
'id',
MagentoFrameworkDBDdlTable::TYPE_INTEGER,
null,
['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
''
)
->addColumn(
'mage_order_id',
MagentoFrameworkDBDdlTable::TYPE_TEXT,
255,
['nullable' => false, 'default' => ''],
'magento orderid'
);
$setup->getConnection()->createTable($table);


I need to insert multiple records for each table.



How this can be achieved using installer. Can anyone look into this and update me your answer please.









share























  • You wanna to insert records into your table ??

    – Prathap Gunasekaran
    5 mins ago











  • @PrathapGunasekaran, yes I have created 2 tables, need to insert multiple records for each table

    – jafar pinjar
    3 mins ago











  • For adding data to the tables you required installData or UpgradeData please follow this

    – ABHISHEK TRIPATHI
    1 min ago













  • @ABHISHEKTRIPATHI, can you update me InstallData.php code for my tables just with sample data please

    – jafar pinjar
    31 secs ago
















0















I have created multiple table schema using setup script like below.



Setup/InstallSchema.php



   namespace VendorModuleSetup;
use MagentoFrameworkSetupInstallSchemaInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupSchemaSetupInterface;

class InstallSchema implements InstallSchemaInterface
{

public function install(SchemaSetupInterface $setup,
ModuleContextInterface $context)
{
/**
* Create table 'tbl_test1'
*/
$table = $setup->getConnection()
->newTable($setup->getTable('tbl_test1'))
->addColumn(
'id',
MagentoFrameworkDBDdlTable::TYPE_INTEGER,
null,
['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
'Pod ID'
)
->addColumn(
'name',
MagentoFrameworkDBDdlTable::TYPE_TEXT,
255,
['nullable' => false, 'default' => ''],
'name'
);
$setup->getConnection()->createTable($table);

/**
* Create table 'tbl_test_2'
*/
$table = $setup->getConnection()
->newTable($setup->getTable('tbl_test_2'))
->addColumn(
'id',
MagentoFrameworkDBDdlTable::TYPE_INTEGER,
null,
['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
''
)
->addColumn(
'mage_order_id',
MagentoFrameworkDBDdlTable::TYPE_TEXT,
255,
['nullable' => false, 'default' => ''],
'magento orderid'
);
$setup->getConnection()->createTable($table);


I need to insert multiple records for each table.



How this can be achieved using installer. Can anyone look into this and update me your answer please.









share























  • You wanna to insert records into your table ??

    – Prathap Gunasekaran
    5 mins ago











  • @PrathapGunasekaran, yes I have created 2 tables, need to insert multiple records for each table

    – jafar pinjar
    3 mins ago











  • For adding data to the tables you required installData or UpgradeData please follow this

    – ABHISHEK TRIPATHI
    1 min ago













  • @ABHISHEKTRIPATHI, can you update me InstallData.php code for my tables just with sample data please

    – jafar pinjar
    31 secs ago














0












0








0








I have created multiple table schema using setup script like below.



Setup/InstallSchema.php



   namespace VendorModuleSetup;
use MagentoFrameworkSetupInstallSchemaInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupSchemaSetupInterface;

class InstallSchema implements InstallSchemaInterface
{

public function install(SchemaSetupInterface $setup,
ModuleContextInterface $context)
{
/**
* Create table 'tbl_test1'
*/
$table = $setup->getConnection()
->newTable($setup->getTable('tbl_test1'))
->addColumn(
'id',
MagentoFrameworkDBDdlTable::TYPE_INTEGER,
null,
['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
'Pod ID'
)
->addColumn(
'name',
MagentoFrameworkDBDdlTable::TYPE_TEXT,
255,
['nullable' => false, 'default' => ''],
'name'
);
$setup->getConnection()->createTable($table);

/**
* Create table 'tbl_test_2'
*/
$table = $setup->getConnection()
->newTable($setup->getTable('tbl_test_2'))
->addColumn(
'id',
MagentoFrameworkDBDdlTable::TYPE_INTEGER,
null,
['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
''
)
->addColumn(
'mage_order_id',
MagentoFrameworkDBDdlTable::TYPE_TEXT,
255,
['nullable' => false, 'default' => ''],
'magento orderid'
);
$setup->getConnection()->createTable($table);


I need to insert multiple records for each table.



How this can be achieved using installer. Can anyone look into this and update me your answer please.









share














I have created multiple table schema using setup script like below.



Setup/InstallSchema.php



   namespace VendorModuleSetup;
use MagentoFrameworkSetupInstallSchemaInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupSchemaSetupInterface;

class InstallSchema implements InstallSchemaInterface
{

public function install(SchemaSetupInterface $setup,
ModuleContextInterface $context)
{
/**
* Create table 'tbl_test1'
*/
$table = $setup->getConnection()
->newTable($setup->getTable('tbl_test1'))
->addColumn(
'id',
MagentoFrameworkDBDdlTable::TYPE_INTEGER,
null,
['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
'Pod ID'
)
->addColumn(
'name',
MagentoFrameworkDBDdlTable::TYPE_TEXT,
255,
['nullable' => false, 'default' => ''],
'name'
);
$setup->getConnection()->createTable($table);

/**
* Create table 'tbl_test_2'
*/
$table = $setup->getConnection()
->newTable($setup->getTable('tbl_test_2'))
->addColumn(
'id',
MagentoFrameworkDBDdlTable::TYPE_INTEGER,
null,
['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
''
)
->addColumn(
'mage_order_id',
MagentoFrameworkDBDdlTable::TYPE_TEXT,
255,
['nullable' => false, 'default' => ''],
'magento orderid'
);
$setup->getConnection()->createTable($table);


I need to insert multiple records for each table.



How this can be achieved using installer. Can anyone look into this and update me your answer please.







magento2 setup-script installdata





share












share










share



share










asked 6 mins ago









jafar pinjarjafar pinjar

745414




745414













  • You wanna to insert records into your table ??

    – Prathap Gunasekaran
    5 mins ago











  • @PrathapGunasekaran, yes I have created 2 tables, need to insert multiple records for each table

    – jafar pinjar
    3 mins ago











  • For adding data to the tables you required installData or UpgradeData please follow this

    – ABHISHEK TRIPATHI
    1 min ago













  • @ABHISHEKTRIPATHI, can you update me InstallData.php code for my tables just with sample data please

    – jafar pinjar
    31 secs ago



















  • You wanna to insert records into your table ??

    – Prathap Gunasekaran
    5 mins ago











  • @PrathapGunasekaran, yes I have created 2 tables, need to insert multiple records for each table

    – jafar pinjar
    3 mins ago











  • For adding data to the tables you required installData or UpgradeData please follow this

    – ABHISHEK TRIPATHI
    1 min ago













  • @ABHISHEKTRIPATHI, can you update me InstallData.php code for my tables just with sample data please

    – jafar pinjar
    31 secs ago

















You wanna to insert records into your table ??

– Prathap Gunasekaran
5 mins ago





You wanna to insert records into your table ??

– Prathap Gunasekaran
5 mins ago













@PrathapGunasekaran, yes I have created 2 tables, need to insert multiple records for each table

– jafar pinjar
3 mins ago





@PrathapGunasekaran, yes I have created 2 tables, need to insert multiple records for each table

– jafar pinjar
3 mins ago













For adding data to the tables you required installData or UpgradeData please follow this

– ABHISHEK TRIPATHI
1 min ago







For adding data to the tables you required installData or UpgradeData please follow this

– ABHISHEK TRIPATHI
1 min ago















@ABHISHEKTRIPATHI, can you update me InstallData.php code for my tables just with sample data please

– jafar pinjar
31 secs ago





@ABHISHEKTRIPATHI, can you update me InstallData.php code for my tables just with sample data please

– jafar pinjar
31 secs ago










1 Answer
1






active

oldest

votes


















0














You can use an InstallData script

Try this:



<?php

namespace VendorModuleSetup;

use MagentoFrameworkSetupInstallDataInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;

class InstallData implements InstallDataInterface
{
/**
* {@inheritdoc}
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();

$setup->getConnection()->insert(
$setup->getTable('tbl_test1'),
[
'id' => 1,
'name' => 'name 1'
]
);

$setup->getConnection()->insert(
$setup->getTable('tbl_test_2'),
[
'id' => 1,
'mage_order_id' => 'mage_order_id'
]
);

$setup->endSetup();
}
}




share
























    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
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f268275%2finsert-multiple-records-to-multiple-custom-tables-through-install-script-in-mage%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You can use an InstallData script

    Try this:



    <?php

    namespace VendorModuleSetup;

    use MagentoFrameworkSetupInstallDataInterface;
    use MagentoFrameworkSetupModuleContextInterface;
    use MagentoFrameworkSetupModuleDataSetupInterface;

    class InstallData implements InstallDataInterface
    {
    /**
    * {@inheritdoc}
    */
    public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    {
    $setup->startSetup();

    $setup->getConnection()->insert(
    $setup->getTable('tbl_test1'),
    [
    'id' => 1,
    'name' => 'name 1'
    ]
    );

    $setup->getConnection()->insert(
    $setup->getTable('tbl_test_2'),
    [
    'id' => 1,
    'mage_order_id' => 'mage_order_id'
    ]
    );

    $setup->endSetup();
    }
    }




    share




























      0














      You can use an InstallData script

      Try this:



      <?php

      namespace VendorModuleSetup;

      use MagentoFrameworkSetupInstallDataInterface;
      use MagentoFrameworkSetupModuleContextInterface;
      use MagentoFrameworkSetupModuleDataSetupInterface;

      class InstallData implements InstallDataInterface
      {
      /**
      * {@inheritdoc}
      */
      public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
      {
      $setup->startSetup();

      $setup->getConnection()->insert(
      $setup->getTable('tbl_test1'),
      [
      'id' => 1,
      'name' => 'name 1'
      ]
      );

      $setup->getConnection()->insert(
      $setup->getTable('tbl_test_2'),
      [
      'id' => 1,
      'mage_order_id' => 'mage_order_id'
      ]
      );

      $setup->endSetup();
      }
      }




      share


























        0












        0








        0







        You can use an InstallData script

        Try this:



        <?php

        namespace VendorModuleSetup;

        use MagentoFrameworkSetupInstallDataInterface;
        use MagentoFrameworkSetupModuleContextInterface;
        use MagentoFrameworkSetupModuleDataSetupInterface;

        class InstallData implements InstallDataInterface
        {
        /**
        * {@inheritdoc}
        */
        public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
        {
        $setup->startSetup();

        $setup->getConnection()->insert(
        $setup->getTable('tbl_test1'),
        [
        'id' => 1,
        'name' => 'name 1'
        ]
        );

        $setup->getConnection()->insert(
        $setup->getTable('tbl_test_2'),
        [
        'id' => 1,
        'mage_order_id' => 'mage_order_id'
        ]
        );

        $setup->endSetup();
        }
        }




        share













        You can use an InstallData script

        Try this:



        <?php

        namespace VendorModuleSetup;

        use MagentoFrameworkSetupInstallDataInterface;
        use MagentoFrameworkSetupModuleContextInterface;
        use MagentoFrameworkSetupModuleDataSetupInterface;

        class InstallData implements InstallDataInterface
        {
        /**
        * {@inheritdoc}
        */
        public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
        {
        $setup->startSetup();

        $setup->getConnection()->insert(
        $setup->getTable('tbl_test1'),
        [
        'id' => 1,
        'name' => 'name 1'
        ]
        );

        $setup->getConnection()->insert(
        $setup->getTable('tbl_test_2'),
        [
        'id' => 1,
        'mage_order_id' => 'mage_order_id'
        ]
        );

        $setup->endSetup();
        }
        }





        share











        share


        share










        answered 18 secs ago









        magefmsmagefms

        2,1552426




        2,1552426






























            draft saved

            draft discarded




















































            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%2f268275%2finsert-multiple-records-to-multiple-custom-tables-through-install-script-in-mage%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

            “%fieldName is a required field.”, in Magento2 REST API Call for GET Method Type The Next...

            How to change City field to a dropdown in Checkout step Magento 2Magento 2 : How to change UI field(s)...

            夢乃愛華...