foreign key mismatch
how do i create a unique constraint on
When i do
product_numproduct_num, Store.store_numStore.store_num, Store.chainNameStore.chainNameexport const Store = sqliteTable(
"Store",
{
id: text("id").primaryKey().unique(),
store_num: text("store_num").notNull(),
chain_name: text("chain_name").notNull(),
...
},
(t) => ({
unique: unique().on(t.store_num, t.chain_name),
})
);
export const Product = sqliteTable(
"Product",
{
id: text("id").primaryKey().unique(),
product_num: text("product_num").notNull(),
store_num: text("store_num")
.notNull()
.references(() => Store.store_num),
chainName: text("chainName")
.notNull()
.references(() => Store.chain_name),
...
},
(t) => ({
unique: unique().on(t.product_num, t.store_num, t.chainName), // how do i create a unique contraint on product_num, Store.store_num, Store.chainName
})
);export const Store = sqliteTable(
"Store",
{
id: text("id").primaryKey().unique(),
store_num: text("store_num").notNull(),
chain_name: text("chain_name").notNull(),
...
},
(t) => ({
unique: unique().on(t.store_num, t.chain_name),
})
);
export const Product = sqliteTable(
"Product",
{
id: text("id").primaryKey().unique(),
product_num: text("product_num").notNull(),
store_num: text("store_num")
.notNull()
.references(() => Store.store_num),
chainName: text("chainName")
.notNull()
.references(() => Store.chain_name),
...
},
(t) => ({
unique: unique().on(t.product_num, t.store_num, t.chainName), // how do i create a unique contraint on product_num, Store.store_num, Store.chainName
})
);When i do
drizzle-kit push:sqlitedrizzle-kit push:sqliteLibsqlError: SQLITE_UNKNOWN: SQLite error: foreign key mismatch - "Product" referencing "Store"
at mapHranaError (file:///D:/../../node_modules/@libsql/client/lib-esm/hrana.js:257:16)
at HttpClient.execute (file:///D:/../../node_modules/@libsql/client/lib-esm/http.js:56:19)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async TursoSqlite.run (D:\..\\node_modules\drizzle-kit\bin.cjs:25414:9)
at async Command.<anonymous> (D:\gitpersonal\sg-backend\node_modules\drizzle-kit\bin.cjs:63360:9) {
code: 'SQLITE_UNKNOWN',
[cause]: [ResponseError: SQLite error: foreign key mismatch - "Product" referencing "Store"] {
message: 'SQLite error: foreign key mismatch - "Product" referencing "Store"',LibsqlError: SQLITE_UNKNOWN: SQLite error: foreign key mismatch - "Product" referencing "Store"
at mapHranaError (file:///D:/../../node_modules/@libsql/client/lib-esm/hrana.js:257:16)
at HttpClient.execute (file:///D:/../../node_modules/@libsql/client/lib-esm/http.js:56:19)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async TursoSqlite.run (D:\..\\node_modules\drizzle-kit\bin.cjs:25414:9)
at async Command.<anonymous> (D:\gitpersonal\sg-backend\node_modules\drizzle-kit\bin.cjs:63360:9) {
code: 'SQLITE_UNKNOWN',
[cause]: [ResponseError: SQLite error: foreign key mismatch - "Product" referencing "Store"] {
message: 'SQLite error: foreign key mismatch - "Product" referencing "Store"',