小编Tài*_*yễn的帖子

Magento 2 在模块中创建多数据库表

我创建了一个名为 name 的模块MyCompany\MyModule。在这个模块中,我想创建大约 3 或 4 个 db 表,例如:greeting_message、greeting_post、greeting_comment。然后,我在Setup下面创建了文件夹MyCompany\MyModule并添加了一个文件InstallSchema.php 这是代码:

<?php

/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace MyCompany\MyModle\Setup;
use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;

/**
 * @codeCoverageIgnore
 */
class InstallSchema implements InstallSchemaInterface
{
    /**
     * {@inheritdoc}
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
     */
    public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
    {
        /**
         * Create table 'greeting_message'
         */
        $table = $setup->getConnection()
            ->newTable($setup->getTable('greeting_message'))
            ->addColumn(
                'greeting_id',
                \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                null,
                ['identity' => …
Run Code Online (Sandbox Code Playgroud)

mysql database magento2

2
推荐指数
1
解决办法
1633
查看次数

标签 统计

database ×1

magento2 ×1

mysql ×1