question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@default(autoincrement()) not working on non id integer fields

See original GitHub issue

I am having an id field in my model that is not primary but I want it to be a autoincrement field. So, for this, I just added @default(autoincrement()) in the front of my id field. But this is not working id is not autoincrementing and even I am not able to create if I did not explicitly pass the id filed. This is my model.

model Mail {
    id Int   @default(autoincrement())
    createdAt  DateTime   @default(now())
    updatedAt  DateTime   @updatedAt
    body String
    to String
    from String
    subject String
    messageId String @id
    date DateTime
    attachments Attachment[]
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
do4grcommented, Jul 27, 2020

As per the linked investigation issue (https://github.com/prisma/prisma-engines/issues/903), this would work on Postgres and MySQL but would not work on SQLite. On MySQL the auto_increment column would also need to have an index defined.

We need to decide whether we should allow this if a supporting db is specified.

1reaction
tomhoulecommented, Jul 22, 2020

Linking corresponding engines issue: https://github.com/prisma/prisma-engines/issues/903

Read more comments on GitHub >

github_iconTop Results From Across the Web

MySQL Tutorial :: 7.9 Using AUTO_INCREMENT
The AUTO_INCREMENT attribute can be used to generate a unique identity for new rows: CREATE TABLE animals ( id MEDIUMINT NOT NULL AUTO_INCREMENT, ......
Read more >
unable to create autoincrementing primary key with flask ...
The error you're getting is as a result of attempting to populate the table with an id attribute. Your insert query shouldn't at...
Read more >
SQL AUTO INCREMENT a Field - W3Schools
AUTO INCREMENT Field. Auto-increment allows a unique number to be generated automatically when a new record is inserted into a table.
Read more >
Defining an Auto Increment Primary Key in PostgreSQL - Chartio
Learn how to define an auto increment primary key in PostgreSQL. ... CREATE TABLE books ( id SERIAL PRIMARY KEY, title VARCHAR(100) NOT...
Read more >
Generated Values - EF Core - Microsoft Learn
You can configure a default value on a property: ... a numeric primary key in SQL Server is automatically set up to be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found