Magento2 Magento 2-从自定义架构创建db表时出错
我正在尝试为Magento 2创建一个自定义模块,并在/Setup/InstallSchema.php中定义了模式 运行“php bin/magento安装程序:升级”时,我收到错误: 调用未定义的函数Test/Connector/Setup/getConnection() 模块已启用并正确显示在配置文件中。我尝试运行的架构文件是:Magento2 Magento 2-从自定义架构创建db表时出错,magento2,Magento2,我正在尝试为Magento 2创建一个自定义模块,并在/Setup/InstallSchema.php中定义了模式 运行“php bin/magento安装程序:升级”时,我收到错误: 调用未定义的函数Test/Connector/Setup/getConnection() 模块已启用并正确显示在配置文件中。我尝试运行的架构文件是: <?php namespace Test\Connector\Setup; use Magento\Framework\Setup\InstallSche
<?php
namespace Test\Connector\Setup;
use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\DB\Ddl\Table;
class InstallSchema implements InstallSchemaInterface
{
public function install(SchemaSetupInterface $setup, ModuleContextInterface
$context) {
$installer = $setup;
$installer->startSetup();
$tableName = $installer->getTable('test_connector_settings');
if ($installer->getConnection()->isTableExists($tableName) != true) {
$table = $installer->getConnection()
->newTable($installer->getTable('ipos_connector_settings'))
->addColumn('id', Table::TYPE_SMALLINT, null, ['identity'=> true, 'nullable'=>false, 'primary'=>true], 'ID')
->addColumn('api_url', Table::TYPE_TEXT, 255, ['nullable'=>true], 'API URL')
->addColumn('api_user', Table::TYPE_TEXT, 100, ['nullable'=>false], 'API User Name')
->addColumn('api_password', Table::TYPE_TEXT, 100, ['nullable'=>false], 'API Password');
$installer-getConnection()->createTable($table);
}
$installer->endSetup();
}
}
请更改此行
$installer-getConnection()->createTable($table); // your code line.
与
谢谢你,吉坦德拉,尽管我现在确实感到有点尴尬。我太专注于getConnection()的前两个实例了,但一直没有到第三个。吸取的教训是,解决问题的第一步是使用验证器!
$installer->getConnection()->createTable($table);