DT
Drizzle Team17mo ago
z

FK identifier will be truncated... how to specify my own?

Im running into a warning because the FK constraint identifier is too long and will be automatically truncated. I would prefer to specify my own indentifier instead of it getting truncated... Is there a way to achieve this? any help is appreciated! ❤️
5 Replies
z
zOP17mo ago
Here is the exact warning:
{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '42622',
message: 'identifier "very_long_id_fk" will be truncated to "very_lon"',
where: 'SQL statement ...',
file: 'scansup.c',
line: '99',
routine: 'truncate_identifier'
}
{
severity_local: 'NOTICE',
severity: 'NOTICE',
code: '42622',
message: 'identifier "very_long_id_fk" will be truncated to "very_lon"',
where: 'SQL statement ...',
file: 'scansup.c',
line: '99',
routine: 'truncate_identifier'
}
Angelelz
Angelelz17mo ago
I think the ability the name our oen FK is comming. This problem will be no more
z
zOP17mo ago
awesome! ty
Radu
Radu14mo ago
any fix for this?
baronnoraz
baronnoraz14mo ago
This works for me using MySQL and Drizzle...
export const userAccount = mysqlTable(
'user_account',
{
id: bigint('id', { mode: 'number' }).primaryKey().autoincrement(),
userId: bigint('user_id', { mode: 'number' }).notNull(),
type: varchar('type', { length: 255 }).notNull(),
salt: varchar('salt', { length: 128 }).notNull(),
password: varchar('password', { length: 255 }).notNull(),
createdAt: timestamp('created_at').notNull().defaultNow(),
},
(ua) => {
return {
userIdIndex: index('ix_user_account_user_id').on(ua.userId),
typeIndex: index('ix_user_account_type').on(ua.type),
userIdTypeIndex: uniqueIndex('ux_user_account_user_id_type').on(ua.userId, ua.type),
userForeignKey: foreignKey({
columns: [ua.userId],
foreignColumns: [user.id],
name: 'fk_user_account_user_id'
})
};
},
);
export const userAccount = mysqlTable(
'user_account',
{
id: bigint('id', { mode: 'number' }).primaryKey().autoincrement(),
userId: bigint('user_id', { mode: 'number' }).notNull(),
type: varchar('type', { length: 255 }).notNull(),
salt: varchar('salt', { length: 128 }).notNull(),
password: varchar('password', { length: 255 }).notNull(),
createdAt: timestamp('created_at').notNull().defaultNow(),
},
(ua) => {
return {
userIdIndex: index('ix_user_account_user_id').on(ua.userId),
typeIndex: index('ix_user_account_type').on(ua.type),
userIdTypeIndex: uniqueIndex('ux_user_account_user_id_type').on(ua.userId, ua.type),
userForeignKey: foreignKey({
columns: [ua.userId],
foreignColumns: [user.id],
name: 'fk_user_account_user_id'
})
};
},
);

Did you find this page helpful?