I am facing this issue- type "time(0)" does not exist. How can I fix this ?
NeonDbError: type "time(0)" does not exist
at execute (E:\Big-project\maidaan\node_modules@neondatabase\serverless\index.js:1544:48)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at migrate (E:\Big-project\maidaan\node_modules\src\neon-http\migrator.ts:41:5)
at main (e:\Big-project\maidaan\db\migrate.ts:9:21) {
code: '42704',
sourceError: undefined
}
also check migration code in the image
7 Replies
Hello, @kuber! Could you show your schema file please? I think this error is related to some type in your schema.
yeah sure
I have 3 schema files
booking.schema.ts, turf.schema.ts and user.schema.ts
@kuber There is a bug related to generating migrations for the
time
data type with precision. I encountered the same issue with my schema. I plan to create an issue for this so that it can be fixed in the future. For now, you can manually update your migration file by removing ""
near type. Also, you can initially generate the migration for the time
type without specifying any precision. Then, update your schema in Drizzle to include the precision you need, and generate the migration againThanks, that fixes this error but now I am encountering another error about the foreign key constraint.
Here is the SQL statements ->
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "booking" ADD CONSTRAINT "booking_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "booking" ADD CONSTRAINT "booking_turfId_turf_id_fk" FOREIGN KEY ("turfId") REFERENCES "turf"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "account" ADD CONSTRAINT "account_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
@kuber I believe the issue may be related to the differing data types of your primary key and foreign key. Consider changing the type of
turfId
to uuid
to match your primary key. Additionally, it's not necessary to specify notNull
and unique
for the primary key, as these attributes are inherently applied to primary keys by default. To properly implement these changes, remove any existing constraints and tables before creating new migrations to ensure that the database schema is correctly updated.Actually, I've tried this before but this doesn't work
still a big thanks to you