我有一个InstallSchema.php,只是没有在数据库中创建必要的表。模式的代码如下所示:
<?php
namespace MyVendor\Helpdesk\Setup;
use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
/**
* @codeCoverageIgnore
*/
class InstallSchema implements InstallSchemaInterface
{
public function install(SchemaSetupInterface $setup,
ModuleContextInterface $context)
{
$installer = $setup;
$installer->startSetup();
$table = $installer->getConnection()
->newTable($installer->getTable('myvendor_helpdesk_ticket'))
->addColumn(
'ticket_id',
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
null,
['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
'Ticket Id'
)
->addColumn(
'customer_id',
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
null,
['unsigned' => true],
'Customer Id'
)
->addColumn(
'title',
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
null,
['nullable' => false],
'Title'
)
->addColumn(
'severity',
\Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
null,
['nullable' => false],
'Severity'
)
->addColumn(
'created_at',
\Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
null,
['nullable' => false],
'Created At'
)
->addColumn(
'status',
\Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
null,
['nullable' => false],
'Status'
)
->addIndex(
$installer->getIdxName('myvendor_helpdesk_ticket', ['customer_id']),
['customer_id']
)
->addForeignKey(
$installer->getFkName('myvendor_helpdesk_ticket', 'customer_id', 'customer_entity', 'entity_id'),
'customer_id',
$installer->getTable('customer_entity'),
'entity_id',
\Magento\Framework\DB\Ddl\Table::ACTION_SET_NULL
)
->setComment('myvendor Helpdesk Ticket');
$installer->getConnection()->createTable($table);
$installer->endSetup();
}
}
我运行了以下命令:
php bin/magento setup:upgrade
php bin/magento setup:db-schema:upgrade
没有错误,但是,当我进入我的页面时,我收到了休闲错误:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'magento.myvendor_helpdesk_ticket' doesn't exist
请帮忙。
您是否在任何地方定义了“ myvendor_helpdesk_ticket”?它可能只是在installer-> getTable()上失败。
—
dbcn
您定义的意思是什么?可以请你提供一个小例子
—
Lachezar Raychev
我确实创建了一个ResourceModel,在其中执行app / code / MyVendor / Helpdesk / Model / ResourceModel / Ticket.php:$ this-> _ init('myvendor_helpdesk_ticket','ticket_id'); 如果是定义它...我发布的代码中其他所有包含'myvendor_helpdesk_ticket'字符串的地方
—
Lachezar Raychev 2016年
我用“-> newTable('myvendor_helpdesk_ticket')”替换了“-> newTable($ installer-> getTable('myvendor_helpdesk_ticket'))” ...仍然没有
—
Lachezar Raychev
尝试从表中删除
—
马吕斯
setup_module
的纪录module = 'MyVendor_Helpdesk'