Magento 2 Database – How to Properly Remove DB Table Prefix

databasemagento2

I just removed the table prefix ('mg_') from my magento 2.0.2 installation using phpmyadmin. I also updated app/etc/env.php to not include any db table prefix. After that I flushed all caches (php bin/magento cache:clean) and reindexed everything (php bin/magento indexer:reindex). everything works fine, EXCEPT

When I hit the 'Place Order' button at the end of the checkout I get an SQL-error:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mydb.mg_sequence_order_1' doesn't exist, query was: INSERT INTO `mg_sequence_order_1` () VALUES ()

Apparently the table prefix is somehow not been removed in this one particular place. Can anyone maybe point me to a way how to proceed?

Best Answer

The sequence table names for orders and entities related to orders are kept in the sales_sequence_meta table.
This statement

select * from sales_sequence_meta;

should give you something like this:

+---------+-------------+----------+--------------------------+
| meta_id | entity_type | store_id | sequence_table           |
+---------+-------------+----------+--------------------------+
|       1 | order       |        0 | mg_sequence_order_0      |
|       2 | invoice     |        0 | mg_sequence_invoice_0    |
|       3 | creditmemo  |        0 | mg_sequence_creditmemo_0 |
|       4 | shipment    |        0 | mg_sequence_shipment_0   |
|       5 | order       |        1 | mg_sequence_order_1      |
|       6 | invoice     |        1 | mg_sequence_invoice_1    |
|       7 | creditmemo  |        1 | mg_sequence_creditmemo_1 |
|       8 | shipment    |        1 | mg_sequence_shipment_1   |
+---------+-------------+----------+--------------------------+

Remove the mg_ prefix from the sequence_table column for each row and you should be good to go.

Related Topic