In Magento 2 - How to remove a column in customer_entity table?
In your setup script, we can use dropColumn
:
$setup->getConnection()->dropColumn($setup->getTable('your_table'), 'your_column');
You can try this simple dropColumn() function in your installer script.
$this->startSetup();
//example:
$this->getConnection()->dropColumn($this->getTable('your_table_definition'), 'your column name', $schemaName = null)
$this->endSetup();
Here is my solution, maybe good for referring for other.
I created Tohq\Customer\Setup\UpgradeSchema.php
file:
<?php
namespace Tohq\Customer\Setup;
use Magento\Framework\Setup\UpgradeSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
/**
* @codeCoverageIgnore
*/
class UpgradeSchema implements UpgradeSchemaInterface
{
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
// Version of module in setup table is less then the give value.
if (version_compare($context->getVersion(), '0.1.4', '<')) {
// get table customer_entity
$eavTable = $setup->getTable('customer_entity');
// Check if the table already exists
if ($setup->getConnection()->isTableExists($eavTable) == true) {
$connection = $setup->getConnection();
// del_flg = column name which you want to delete
$connection->dropColumn($eavTable, 'del_flg');
}
}
}
}