many-to-many foreign key constraint 787 issue

I cannot add a row in my likes_to_questions table even though both user_id and question_id are unique, and the primary key is composed of those two, so as to allow a user to have only 1 like on a question this is my relations
// 📃 LIKES TO QUESTIONS

export const likesToQuestionsTable = sqliteTable(
'likes_to_questions',
{
userId: text('user_id')
.notNull()
.references(() => usersTable.id, { onDelete: 'cascade' }),
questionId: text('question_id')
.notNull()
.references(() => questionsTable.id, { onDelete: 'cascade' }),
},
(t) => ({
pk: primaryKey({ columns: [t.userId, t.questionId] }),
})
)
// 📃 LIKES TO QUESTIONS

export const likesToQuestionsTable = sqliteTable(
'likes_to_questions',
{
userId: text('user_id')
.notNull()
.references(() => usersTable.id, { onDelete: 'cascade' }),
questionId: text('question_id')
.notNull()
.references(() => questionsTable.id, { onDelete: 'cascade' }),
},
(t) => ({
pk: primaryKey({ columns: [t.userId, t.questionId] }),
})
)
attempting to add a new row (see the picture) will result in error 787
No description
2 Replies
piscopancer
piscopancerOP•9mo ago
* I double checked that primaryKey function comes from sqlite adapter
import { integer, primaryKey, sqliteTable, text, type SQLiteColumn } from 'drizzle-orm/sqlite-core'
import { integer, primaryKey, sqliteTable, text, type SQLiteColumn } from 'drizzle-orm/sqlite-core'
* userId and questionId are both primary keys Not only I cannot add new rows, I cannot edit them either, it throws 787
Mykhailo
Mykhailo•9mo ago
You can't add/edit rows only in drizzle studio? Could you please show your error with error message?
Want results from more Discord servers?
Add your server