Magento数据库表概述
Magento数据表数量很大,在我们安装的M2各版本中,共大约有近400张左右的Table。
与传统的Mysql建表方式有所不同,Magento为了达到字段方便扩展,结构灵活,在部分业务场中使用了EAV模式的表结构
数据库EAV的含义
1.EAV的理解:Entity-Attribute-Value/(实体-属性-值)
- 实体:包括要存储的数据类型的信息(客户,产品…)
- 属性:是实体的属性(颜色,大小,高度…)
- 值:是给定属性的值(蓝色,红色,…)
也就是说,在我们传统的一张表,以eav的方式实现时,会被横向拆分为多张数据表。
这样做的好处是:可以方便的扩展字段,自定义字段。
如,我们可以在magento的后台,为商品扩展属性字段,并指定该属性的值采用的类型,如text,select下拉,checkbox等。
magento中使用到EAV模式的场景
用户Customer相关的表:
customer_entity
customer_entity_datetime
customer_entity_decimal
customer_entity_int
customer_entity_text
customer_entity_varchar
客户地址相关表:
customer_address_entity
customer_address_entity_datetime
customer_address_entity_decimal
customer_address_entity_int
customer_address_entity_text
customer_address_entity_varchar
产品表:
catalog_product_entity
catalog_product_entity_datetime
catalog_product_entity_decimal
catalog_product_entity_gallery
catalog_product_entity_int
catalog_product_entity_media_gallery
catalog_product_entity_media_gallery_value
catalog_product_entity_media_gallery_value_to_entity
catalog_product_entity_media_gallery_value_video
catalog_product_entity_text
catalog_product_entity_tier_price
catalog_product_entity_varchar
分类表:
catalog_category_entity
catalog_category_entity_datetime
catalog_category_entity_decimal
catalog_category_entity_int
catalog_category_entity_text
实体类型表:
eav_entity_int
eav_entity_varchar
eav_entity_text
eav_entity_decimal
eav_entity_datetime
PS: 我们在平时的开发中,需要对eav有一个大概的了解,这样在具体的业务逻辑中,才能清楚数据分布在了哪些表中。