# OpenCart Database Tables: Schema and Key Tables in 3.0 and 4.1

> OpenCart 3.0 and 4.1 Database Map: How Many Tables There Are, How They Are Grouped, Which Naming Patterns Repeat, and What Changed in the 4.1 Schema for Module Developers.

Джерело: https://opencartcode.com/en/wiki/dev-database/opencart-database-tables
OpenCart: 3.0, 4.1
Оновлено: 2026-11-25

[OpenCart](https://opencartcode.com/en/wiki/glossary/e-commerce-glossary#opencart) database tables consist of several repeating patterns: the main entity table (`product`, `category`), its translations (`_description` with `language_id`), store binding (`_to_store`), and page layout binding (`_to_layout`). Once you understand these patterns, you can quickly read any part of the schema. In 3.0.5.1 there are 134 tables, in 4.1.0.4 there are 159, and some key tables in 4.1 have changed structure.

Examples are for OpenCart 4.1; in 4.0.x, model triggers and event handling differ. For where the code lives for the models that work with these tables, see the articles [OpenCart model and $this->db](https://opencartcode.com/en/wiki/dev-mvc/opencart-model) and [OpenCart file structure](https://opencartcode.com/en/wiki/dev-architecture/opencart-file-structure).

## Where is the schema described, and how do the versions differ overall?

The source of truth for the schema is different in each branch:

- **OpenCart 3.0:** the `install/opencart.sql` file with ready-made `CREATE TABLE` and demo data.
- **OpenCart 4.1:** a PHP array in `system/helper/db_schema.php` (function `oc_db_schema()`). The installer and upgrader build tables from it, and the demo data is stored separately in `install/opencart.sql`.

All tables have a prefix from the `DB_PREFIX` constant in `config.php`; by default it is `oc_`, but on a specific server it may be different, so in module code always write `DB_PREFIX . "product"`. For configs, see the article [config.php in OpenCart](https://opencartcode.com/en/wiki/dev-architecture/opencart-config-php).

| Release | Tables | Engine | Core table encoding |
| --- | --- | --- | --- |
| 3.0.4.1 | 136 | 134 MyISAM, 2 InnoDB | `utf8` / `utf8_general_ci` |
| 3.0.5.1 | 134 | 132 MyISAM, 2 InnoDB | `utf8mb4` / `utf8mb4_unicode_ci` |
| 4.1.0.4 | 159 | InnoDB | `utf8mb4` / `utf8mb4_unicode_ci` |

Between 3.0.4.1 and 3.0.5.1, two tables disappeared: `order_shipment` and `shipping_courier`. An important consequence of the engine: in 3.0, MyISAM has neither foreign keys nor transactions. In 4.1, `db_schema.php` describes relationships in the `foreign` section, but the installer does not create foreign keys, so integrity between tables in both branches is maintained only by model code. If you delete a product with a direct SQL query, you will leave "orphans" in ten related tables.

> The database connection in 3.0 works in `utf8`, so emojis won't be saved even in the `utf8mb4` table. A JOIN on text fields between a module table and a core table with a different collation gives the error `Illegal mix of collations`; a JOIN on integer ids always works.

## How are the tables grouped?

OpenCart table names speak for themselves, and they are convenient to read in groups:

| Group | Key tables |
| --- | --- |
| Catalog | `product`, `product_description`, `product_to_category`, `product_image`, `product_option`, `product_option_value`, `product_attribute`, `product_discount`, `category`, `category_description`, `category_path`, `manufacturer` |
| Attributes, options, filters | `attribute`, `attribute_group`, `option`, `option_value`, `filter`, `filter_group` and their `_description` |
| Orders | `order`, `order_product`, `order_option`, `order_total`, `order_history`, `order_status` |
| Customers | `customer`, `customer_group`, `address`, `customer_transaction`, `customer_reward` |
| Localisation | `language`, `currency`, `country`, `zone`, `geo_zone`, `tax_class`, `tax_rate` |
| Stores and design | `store`, `layout`, `layout_route`, `layout_module`, `module`, `theme`, `seo_url` |
| System | `setting`, `extension`, `extension_install`, `event`, `modification`, `session`, `cart`, `user`, `user_group` |

A separate note on several tables that modules work with most often:

- `setting` — core and module settings: `store_id`, `code`, `key`, `value`, `serialized`. Arrays are stored as JSON with `serialized = 1`. For details, see the article [setting model and the setting table](https://opencartcode.com/en/wiki/dev-extensions/opencart-module-setting).
- `category_path` — a ready-made [category](https://opencartcode.com/en/wiki/glossary/e-commerce-glossary#category) tree: for each category, rows with all its ancestors (`path_id`) and the level (`level`). Through it, the core finds all subcategories without recursion.
- `cart` — the database cart, bound to `session_id` and `customer_id`.
- `event` and `modification` — registered events and OCMOD modifications of modules.

## Which patterns repeat across the entire schema?

### Translations: _description and language_id

Everything shown to the customer as text is moved into tables with the suffix `_description` and the primary key `(id сутності, language_id)`. For example, `product_description` has `PRIMARY KEY (product_id, language_id)` and the fields `name`, `description`, `tag`, `meta_title`, `meta_description`, `meta_keyword`. Therefore, every query for names has the filter `language_id`, and a module that adds a product must insert a row for each language. In 4.1 this pattern was extended to countries and regions: `country_description` and `zone_description` appeared.

### Stores: _to_store and store_id 0

The tables `product_to_store`, `category_to_store`, `information_to_store`, `manufacturer_to_store` determine in which store an entity is visible. A product without a row in `product_to_store` for the current store will not be found on the [storefront](https://opencartcode.com/en/wiki/glossary/e-commerce-glossary#storefront). The main store has `store_id = 0`, and in the table `store` it is **absent**: there are only additional stores there, while the settings of the main store are in `setting` with `store_id = 0`.

### Page layouts: _to_layout

`product_to_layout`, `category_to_layout` and others define which layout a specific page uses, and `layout_module` defines which modules are displayed in the positions of that layout.

Example

```sql
SELECT p.product_id, p.model, p.price, pd.name
FROM oc_product p
JOIN oc_product_description pd ON (pd.product_id = p.product_id AND pd.language_id = 1)
JOIN oc_product_to_store p2s ON (p2s.product_id = p.product_id AND p2s.store_id = 0)
WHERE p.status = 1
ORDER BY pd.name
LIMIT 20;
```

The value `language_id = 1` here is for illustration only: language ids depend on the installation. In code, take it from `$this->config->get('config_language_id')`, and the store from `config_store_id`.

## What changed in the OpenCart 4.1 schema?

Most 4.1 tables match 3.0 by name, but there are differences in key tables that break direct SQL queries from modules:

| What | OpenCart 3.0 | OpenCart 4.1 |
| --- | --- | --- |
| Product codes | columns `sku`, `upc`, `ean`, `jan`, `isbn`, `mpn` in `product` | table `product_code` (`product_id`, `code`, `value`) and the reference `identifier` (SKU, UPC, EAN, JAN, etc.) |
| Product variants | none | columns `master_id`, `variant`, `override` in `product` |
| Special prices | separate `product_special` | `product_discount` rows with `special = 1` and the column `type` |
| Product views | column `product.viewed` | tables `product_viewed` and `product_report` |
| Recurring payments | `recurring`, `order_recurring`, `product_recurring` | `subscription`, `subscription_plan`, `product_subscription` and others |
| Gift vouchers | `voucher`, `voucher_theme`, `order_voucher` | not in the core schema |
| SEO URLs | `seo_url.query` = `product_id=48` | `seo_url.key` = `product_id`, `value` = `48`, plus `sort_order` |
| Payment method in order | `order.payment_method` varchar(128) and `payment_code` | `order.payment_method` text with JSON, without `payment_code` |
| Customer | has `salt`, `cart`, `wishlist`, `address_id`, `fax` | these columns are absent |

This is what `seo_url` looks like in 3.0:

`install/opencart.sql` · OpenCart 3.0.5.1 · lines 3699–3708

```sql
CREATE TABLE `oc_seo_url` (
  `seo_url_id` int(11) NOT NULL AUTO_INCREMENT,
  `store_id` int(11) NOT NULL,
  `language_id` int(11) NOT NULL,
  `query` varchar(255) NOT NULL,
  `keyword` varchar(255) NOT NULL,
  PRIMARY KEY (`seo_url_id`),
  KEY `query` (`query`),
  KEY `keyword` (`keyword`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
```

In 4.1, instead of one `query` row there is a pair `key` (varchar(64)) and `value` (varchar(255)), and `keyword` has been expanded to varchar(768). A 3.0 module query of the form `WHERE query = 'product_id=48'` must be rewritten for 4.1 as `WHERE `key` = 'product_id' AND `value` = '48'`. For the table itself, see the article [seo_url in OpenCart](https://opencartcode.com/en/wiki/dev-mvc/seo-url-opencart).

New table groups in 4.1: blog (`article`, `topic` with descriptions and bindings), tasks `cron`, `startup`, `antispam`, `gdpr`, tokens and authorization (`customer_token`, `customer_authorize`, `user_token`, `user_authorize`, `user_login`), reports (`product_report`, `download_report`, `marketing_report`).

## Which indexes exist, and where are they missing?

Core indexes are minimal, and it is worth knowing this before writing your own queries. For comparison of several tables:

| Table | OpenCart 3.0 | OpenCart 4.1 |
| --- | --- | --- |
| `order` | primary key only | additionally `email` and `order_status_id` |
| `customer` | primary key only | additionally `email` |
| `product_description` | `name` | `name` |
| `product_to_category` | `category_id` | `category_id` |
| `order_product` | `order_id` | `order_id` |

The practical conclusion: in 3.0, selecting orders by status or customers by email on a large database performs a full table scan. If a module regularly makes such queries, check the plan via `EXPLAIN` and, if necessary, suggest that the store owner add an index. Changing core tables from the `install()` module without warning is not advisable: it affects all other modules and future upgrades.

## How to work with the schema safely from a module?

- **Read through core models where possible.** Models already account for language, store, [customer group](https://opencartcode.com/en/wiki/glossary/e-commerce-glossary#customer-group), and status, while direct SQL easily skips one of these conditions.
- **Write through core models where possible.** `editProduct()` or `deleteProduct()` update and clean up a dozen related tables; a manual `DELETE FROM product` won't do this, and there are no foreign keys to act as a safety net.
- **Keep your own data in your own tables** with the module prefix, on InnoDB, and do not add columns to core tables. For how to design them, see the article [custom module tables in OpenCart](https://opencartcode.com/en/wiki/dev-extensions/opencart-module-tables).
- **Check the schema against the version.** Before a direct query, open `install/opencart.sql` (3.0) or `system/helper/db_schema.php` (4.1) and verify that the column exists there.
- **Always filter by `language_id` and `store_id`** in tables where they exist, otherwise you will get duplicate rows.

## Summary

- 3.0.4.1 has 136 tables, 3.0.5.1 has 134, and 4.1.0.4 has 159; the prefix is taken from `DB_PREFIX`.
- The 3.0 schema is described in `install/opencart.sql`, and the 4.1 schema is in `system/helper/db_schema.php`.
- Patterns: `_description` with `language_id`, `_to_store` with `store_id` (the main store is 0, and it is absent from `store`), `_to_layout` for page layouts.
- In 4.1, product codes, specials, SEO URLs, subscriptions, and the [payment method](https://opencartcode.com/en/wiki/glossary/e-commerce-glossary#payment-method) format have changed; there are no vouchers in the core schema.
- There are no foreign keys in either branch, so write data through core models.

Tables for products, orders, and customers, working with `language_id` and `store_id`, and safe and slow queries are covered separately; see the articles in the [Database](https://opencartcode.com/en/wiki/dev-database) section.

## FAQ

**How do I find the exact table prefix on my server?**

Open config.php in the store root and find the DB_PREFIX constant. The same constant must be in admin/config.php.

**Can I convert OpenCart 3.0 tables from MyISAM to InnoDB?**

Technically yes, the core does not depend on the storage engine, but do it on a copy of the database and with a backup. Locking behavior and memory requirements differ between engines, so check your modules and the load after the change.

**Where is the customer's cart content stored?**

In the cart table, linked to session_id and, for a logged-in customer, also to customer_id. The core reads the products and prices for the cart from the catalog tables every time.
