foreign key mismatch
how do i create a unique constraint on
product_num
, Store.store_num
, Store.chainName
When i do drizzle-kit push:sqlite
4 Replies
instead of
unique: unique().on(t.product_num, t.store_num, t.chainName)
if i use unique: unique().on(t.product_num, Store.store_num, Store.chain_name)
i get
OR
@mariojuanaaa any reason not to replace the store_num and chainName columns in the Product table with just a storeId foreign key?
The goal is to have a unique constraint on the Product.product_num, Store.store_num and Store.chain_name. Basically i want a product to be unique in a given store_num and chain_name.
ie, there can only be 1 product
abc123
at walmart #5123
Your response from my understanding is adding a foreign key, which i can do, but i want the unique contraint to be added@mariojuanaaa if you use the primary key of store (id) as a foreign key on product (storeId), then you just need a unique on the product table of storeId and product_num
That way a product num is unique for a given store, which already has the unique store_num and chainName defined on the store table.