Nullable field cannot be inserted or updated

Hi! I've already broken my head, I've asked several ai chats why this might be an error, but they don't know why the error occurs

The problem is that I can't create/update the channels record's userId fields when the userId isn't set to .notNull()

When I bet .notNull() everything works for me, but I need the user Id to be an optional field

export const channels = pgTable('channels', {
  id: integer().primaryKey().generatedAlwaysAsIdentity(),
  channelId: text('channelId').notNull().unique(),

  userId: integer('userId'),

  isActive: boolean('isActive').default(false).notNull(),

  createdAt: timestamp('created_at').notNull().defaultNow(),
  updatedAt: timestamp('updated_at').notNull().defaultNow(),
});

export const channelsRelations = relations(channels, ({ one }) => ({
  user: one(users, {
    fields: [channels.userId],
    references: [users.id],
  }),
}));


Thank you in advance for any hints :silly:
image.png
image.png
Was this page helpful?