[Documentation] Example schema for cockroachdb is not working
See original GitHub issueBug description
In the docs with cockroachdb selected (https://www.prisma.io/docs/getting-started/setup-prisma/start-from-scratch/relational-databases/using-prisma-migrate-typescript-cockroachdb)
This is the example schema… which does not work The `autoincrement()` default function is defined only on BigInt fields on CockroachDB. Use sequence() if you want an autoincrementing Int field.
model Post {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
title String @db.VarChar(255)
content String?
published Boolean @default(false)
author User @relation(fields: [authorId], references: [id])
authorId Int
}
model Profile {
id Int @id @default(autoincrement())
bio String?
user User @relation(fields: [userId], references: [id])
userId Int @unique
}
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
posts Post[]
profile Profile?
}
I found examples like below, but what is the correct way for a classic autoincrement with cockroachdb ?
model Question {
id String @id @default(cuid())
How to reproduce
Try the example schema with provider = "cockroachdb"
Expected behavior
Working autoincrementing id field. Correct documentation.
Prisma information
Environment & setup
- OS:
- Database:
- Node.js version:
Prisma Version
Issue Analytics
- State:
- Created a year ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
[Documentation] Example schema for cockroachdb is not ...
This is the example schema... which does not work The `autoincrement()` default function is defined only on BigInt fields on CockroachDB. Use ...
Read more >Common Errors and Solutions | CockroachDB Docs
This message indicates a client is trying to connect to a node that is either not running or is not listening on the...
Read more >Troubleshoot Common Problems | CockroachDB Docs
This page has instructions for handling errors and troubleshooting problems that may arise during application development.
Read more >Troubleshoot Cluster Setup | CockroachDB Docs
Learn how to troubleshoot issues with starting CockroachDB clusters.
Read more >Troubleshoot CockroachDB Cloud
Check that you are using the correct cluster and database names. You can find these parameters in the CockroachDB Cloud Console by navigating...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Fundamentally, yes - see https://www.cockroachlabs.com/docs/v21.2/sql-faqs#how-do-i-auto-generate-unique-row-ids-in-cockroachdb and related documenation from CockroachDB.
We are currently re-investigating this and might suggest different defaults for primary key columns (you might notice that our current choice does not necessarily represent best practices as communicated by CockroachDB itself) - but for now this works.
I switched back to
Intwithsequence, that way i did not have to change/cast/convert anything for the other frameworks that ran into the JSON Stringify errors…I think there should just be a note that there are still issues around in dealing with
BigIntand maybe a hint forIntwithsequenceif someone wants something similar to a classic autoincrement id.