2017-09-22 77 views
0

我已经在magneto2中创建了一个自定义模块。不使用installschema创建数据库表

模块已启用并在setup_module表中创建了安装文件。 但表未创建。我正在使用magneto 2.0.3版本

这是我的InstallSchema.php文件。

<?php 

    namespace Magento\Bundle\Setup; 

    use Magento\Framework\Setup\InstallSchemaInterface; 
    use Magento\Framework\Setup\ModuleContextInterface; 
    use Magento\Framework\Setup\SchemaSetupInterface; 

    class InstallSchema implements InstallSchemaInterface 
    { 
     /** 
     * {@inheritdoc} 
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength) 
     */ 
     public function install(SchemaSetupInterface $setup, ModuleContextInterface $context) 
     { 
      $installer = $setup; 

      $installer->startSetup(); 
      $table = $installer->getConnection() 
       ->newTable($installer->getTable('test_sample')) 
       ->addColumn(
        'id', 
        \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, 
        null, 
        ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], 
        'Id' 
       ) 
       ->addColumn(
        'name', 
        \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, 
        null, 
        [], 
        'name' 
       ) 
       ->setComment('testing'); 

      $installer->getConnection()->createTable($table); 
      $installer->endSetup(); 
     } 
    } 

回答

0

创建表的代码看起来很好。 但是我认为该文件从未加载并运行。从我所看到的namespace Magento\Bundle\Setup;错误如果这是在您的自定义模块中。