System Information
Strapi Version : v4.0.4
Operating System : Mac OS 12.0
Database : MySQL 5.7.34
Hi, Is there a way to change default primary key type from Integer to BigInt?
Context: I have existing system using Strapi v3 and is using BigInt as the primary key by modifying it directly in DB, but since migrating to v4 I can’t manually change the type anymore, it will break on Admin start.
Error message:
I found out the code that causing this is in here:
}
return { type: 'integer' };
}
case 'decimal': {
return { type: 'decimal', args: [10, 2] };
}
case 'double': {
return { type: 'double' };
}
case 'bigint': {
return { type: 'bigInteger' };
}
case 'enum': {
return { type: 'string' };
}
case 'tinyint': {
return { type: 'boolean' };
}
case 'longtext': {
return { type: 'text', args: ['longtext'] };
There is no Primary Key check for bigint. I guess this is expected for now since integer is being hardcoded as primary key.
I managed to solve this by adding this code inside the bigint case:
case 'bigint': {
if (column.column_key === 'PRI') {
return { type: 'increments', args: [{ primary: true }], unsigned: false };
}
return { type: 'bigInteger' };
}
I guess the next question is:
Is there a way to modify database dialect configuration/provide our own dialect configuration without have to rebuild the strapi source code ourself?
I have similar question, I want to change created_at/updated_at/published_at’s type to ‘timestamptz’ in PostgreSQL.