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
No description
7 Replies
Mykhailo
Mykhailo13mo ago
Hello, @kuber! Could you show your schema file please? I think this error is related to some type in your schema.
kuber
kuberOP13mo ago
yeah sure I have 3 schema files booking.schema.ts, turf.schema.ts and user.schema.ts
No description
No description
No description
Mykhailo
Mykhailo13mo ago
@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 again
No description
kuber
kuberOP13mo ago
Thanks, that fixes this error but now I am encountering another error about the foreign key constraint.
No description
kuber
kuberOP13mo ago
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 $$;
Mykhailo
Mykhailo13mo ago
@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.
kuber
kuberOP12mo ago
Actually, I've tried this before but this doesn't work still a big thanks to you

Did you find this page helpful?