Primary Key Data Type

System Information
  • Strapi Version: 3.6.5
  • Operating System: Windows and Linux
  • Database: Postgres
  • Node Version: 14.X
  • NPM Version: default for 14
  • Yarn Version: 1.22


I’m working on a project and connecting to a pre-existing database. The tables use alphaneumeric id feilds or 14 digit neumeric keys. How can I define a the primary key (id) variable type.


1 Like

Currently it’s not possible to use UUIDs for SQL databases, see:

I’m getting the following error for integer-based keys. Is there a workaround for this?

error error: select distinct “xxx”.* from “xxx” where “xxx”.“customer_id” in ($1) - value “4285311910055” is out of range for type integer

These are integer keys in the PostgresSQL database.

Your exceeding the maximum size of a PG integer (specifically the id field is set to a serial datatype which has a maximum of 2^31-1 or 2,147,483,648).

I can’t image you have already exceeded 2.1 billion entries in your database let alone 4.2 trillion entries

A bigserial type exists but we never implemented because I can’t even begin to fathom a reason why someone would need 9.2 Quintilian entries in a database (the maximum for bigserial) let alone the issues you would have within Javascript with bitint support.

Yes. I understand the constraints on the database or javascript. I wanted to see if I could define the Id key variable type or have a different primary key variable name.

I’m connecting to a pre-existing database for a client. This hardly has 100,000 records. The keys are strangely that large. sadly can’t change them. I imported the database and was able to run strapi project on the data. I face this issue sometimes when i try to fetch models with relations

They must have manually set the data type to big serial and manually set the starting ID to something very high. We won’t be able to handle big serials until the v4 (maybe, I haven’t tested but I will in the beta). But you may hit issues with Javascript and Big Integer support with the existing database.

Functionally though, we don’t plan to support existing databases that weren’t created by a Strapi project.