error: column "trailer_id" cannot be cast automatically to type integer

Hey guys, I'm new with drizzle and I can't figure out what I what I'm doing wrong here is the schema
export const trailers = createTable(
"trailer",
{
id: serial("id").primaryKey(),
registration: varchar("name", { length: 256 }).notNull(),
vin: varchar("vin", { length: 256 }).notNull(),
nextServiceDate: timestamp("next_service_date")
.default(sql`CURRENT_TIMESTAMP + INTERVAL '90 days'`)
.notNull(),
createdAt: timestamp("created_at")
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
updatedAt: timestamp("updatedAt"),
},
(example) => ({
nameIndex: index("name_idx").on(example.registration),
}),
);

export const InspectionType = pgEnum("inspection_type", ["Hire", "Return"]);

export const inspections = createTable("inspection", {
id: serial("id").primaryKey(),
trailerId: integer("trailer_id").references(() => trailers.id),
trailerRegistration: varchar("trailer_registration", {
length: 256,
}).notNull(),
inspectionDate: timestamp("inspection_date")
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
type: InspectionType("inspection_type").notNull(),
createdAt: timestamp("created_at")
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
updatedAt: timestamp("updatedAt"),
});
export const trailers = createTable(
"trailer",
{
id: serial("id").primaryKey(),
registration: varchar("name", { length: 256 }).notNull(),
vin: varchar("vin", { length: 256 }).notNull(),
nextServiceDate: timestamp("next_service_date")
.default(sql`CURRENT_TIMESTAMP + INTERVAL '90 days'`)
.notNull(),
createdAt: timestamp("created_at")
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
updatedAt: timestamp("updatedAt"),
},
(example) => ({
nameIndex: index("name_idx").on(example.registration),
}),
);

export const InspectionType = pgEnum("inspection_type", ["Hire", "Return"]);

export const inspections = createTable("inspection", {
id: serial("id").primaryKey(),
trailerId: integer("trailer_id").references(() => trailers.id),
trailerRegistration: varchar("trailer_registration", {
length: 256,
}).notNull(),
inspectionDate: timestamp("inspection_date")
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
type: InspectionType("inspection_type").notNull(),
createdAt: timestamp("created_at")
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
updatedAt: timestamp("updatedAt"),
});
how would i fix this error?
1 Reply
peterkyle01
peterkyle014w ago
on inspection table you have trailerId an integer which references Id a serial from trailer table ,either make them all an integer or a serial