Mysql Relationship Types of property '_' are incompatible. #1489
-
Type 'MySqlColumn<{ name: "agent_id"; tableName: "students"; dataType: "number"; columnType: "MySqlInt"; data: number; driverParam: string | number; notNull: false; hasDefault: false; enumValues: undefined; baseColumn: never; }, object>' is not assignable to type 'AnyColumn<{ tableName: "users"; }>'.
Types of property '_' are incompatible. Schema export const students = mysqlTable(
"students",
{
id: serial("id").notNull(),
userId: serial("user_id").references(() => users.id),
agentId: int("agent_id"),
countryId: int("country_id"),
studentNo: varchar("student_no", { length: 191 }),
name: varchar("name", { length: 191 }),
createdAt: datetime("created_at", { mode: "string" }),
updatedAt: datetime("updated_at", { mode: "string" }),
},
(table) => {
return {
studentsId: primaryKey(table.id),
};
},
);
export const usersRelations = relations(users, ({ one }) => ({
students: one(users, {
fields: [students.userId],
references: [users.id],
}),
}));
export const users = mysqlTable(
"users",
{
id: serial("id").notNull(),
roleId: int("role_id"),
name: varchar("name", { length: 191 }).notNull(),
email: varchar("email", { length: 191 }).notNull(),
password: varchar("password", { length: 191 }).notNull(),
twoFactorSecret: text("two_factor_secret"),
twoFactorRecoveryCodes: text("two_factor_recovery_codes"),
twoFactorConfirmedAt: timestamp("two_factor_confirmed_at", {
mode: "string",
}),
secret: longtext("secret"),
status: varchar("status", { length: 191 }).default("1"),
rememberToken: varchar("remember_token", { length: 191 }),
createdAt: timestamp("created_at", { mode: "string" }),
updatedAt: timestamp("updated_at", { mode: "string" }),
},
(table) => {
return {
usersId: primaryKey(table.id),
usersEmailUnique: unique("users_email_unique").on(table.email),
};
},
); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Even I adjusted and match the types serial for the relation, alter the tables so that they match with bigint unsigned. Still I got a type error Type 'MySqlColumn<{ name: "user_id"; tableName: "students"; dataType: "number"; columnType: "MySqlSerial"; data: number; driverParam: number; notNull: true; hasDefault: true; enumValues: undefined; baseColumn: never; }, object>' is not assignable to type 'AnyColumn<{ tableName: "users"; }>'. Type 'ColumnTypeConfig<{ name: "user_id"; tableName: "students"; dataType: "number"; columnType: "MySqlSerial"; data: number; driverParam: number; notNull: true; hasDefault: true; enumValues: undefined; baseColumn: never; }, { ...; }>' is not assignable to type 'Required<{ name: string; dataType: ColumnDataType; columnType: string; data: unknown; driverParam: unknown; notNull: boolean; hasDefault: boolean; enumValues: string[] | undefined; tableName: "users"; }>'. |
Beta Was this translation helpful? Give feedback.
You have fields and references backwards: