self reference error
I have just started to learn drizzle and was stuck on some problem
and I get this error =>
'users' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.ts(7022)
const users: any
also when i query my db why do I not get type completions on the returned object.12 Replies
You are getting this error while quering??
No no its in the schema
I have anothe table channel and when i reference it in user it gives the same error
can you share complete schema file then only I will be able to figure out
Btw why are you referencing adminId as users.id??
Last 4th line
I think you mean to reference id of admin table??
Heres the schema
The schema
what I want the user to have two roles if the user is admin he will have multiple editor users and every editor user will have one admin user. Then I thought why not channel table have this logic contained ie the channel will have users as editor and one user as admin. If you have any suggestions in this regard I will be glad to see it
all imports are from drizzle-orm/pg-core right? Can you check
yup
import { timestamp, pgTable, primaryKey, text } from "drizzle-orm/pg-core";
import type { AdapterAccount } from "@auth/core/adapters";
import { relations } from "drizzle-orm";
Okay
I reconstructed the schema and I am not getting any error
Versions
"drizzle-orm": "^0.29.0",
"drizzle-kit": "^0.20.4",
"pg": "^8.11.3",
Even for 0.29.1 it's working fine
I have postgres as core dependency and pg as dev depdency
well pg is not needed I was getting some errors saying pg is missing when I was pushing the migrations so I added it as dev dep
pg is required for runtime don't add it as dev dep
You need it for client
I did
channelId: text("channelId").references(
(): AnyPgColumn => youtubeChannels.id,
{
onDelete: "cascade",
}
),
and it fixed the error