go-gorm / sharding

High performance table sharding plugin for Gorm.
MIT License
276 stars 60 forks source link

sharding Error 1054: Unknown column 'ny_order.deleted_at' in 'where clause' #49

Closed QTTQ closed 2 years ago

QTTQ commented 2 years ago

Your Question

The document you expected this should be explained

Expected answer

QTTQ commented 2 years ago

2022/07/04 19:07:38 Error 1146: Table 'zft.ny_order_12' doesn't exist [0.503ms] [rows:0] SELECT trade_no FROM ny_order WHERE ny = '12' AND ny_order.deleted_at IS NULL

报的是这个 正常不是应该 SELECT trade_no FROM ny_order_12 WHERE ny = '12' AND ny_order_12.deleted_at IS NULL 假如 ny_order_12存在的话

huacnlee commented 2 years ago

贴一下你的配置信息,看不到分表配置,无法确定问题

QTTQ commented 2 years ago

image 我想问一下 查的时候 会默认查 deleted_at is null 的 但是 加上分表后 无论 是nyorder 几 都是ny_order.deleted_at IS NULL 我想根据传的 NumberOfShards 数来对应自动 显示 nyorder.deleted_at IS NULL 比如 query = db.GormDB.Debug().Unscoped().Model(&dbmodel.NyOrder{}).Select("merchant_trade_no").Where("ny", "2").Find(&nyOrderSc) 应该是执行的 SELECT trade_no_02 FROM ny_order WHERE ny = '02' AND ny_order_02.deleted_at IS NULL 而不是 SELECT trade_no_02 FROM ny_order WHERE ny = '02' AND ny_order.deleted_at IS NULL

hyperphoton commented 2 years ago

The problem description is not very clear. If there is still a problem, reopen this issue.

zishiguo commented 1 year ago

I also met this question.