#Auto increment
3 messages · Page 1 of 1 (latest)
Hi @mint vault. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Astro DB does not currently support auto-incrementing IDs directly. When defining your table schema, you need to specify an id column with the primaryKey property, but you must provide a unique value for this id each time you insert a new row into the table.
Here's an example of how you might define a table with an id column:
const Author = defineTable({
columns: {
id: column.number({ primaryKey: true }),
name: column.text(),
}
});
And here's how you might insert a new row into this table, providing a unique id:
await db.insert(Comment).values({
id: uniqueId,
content: 'Hello, world!'
});
In this example, uniqueId would need to be a unique number that you generate or keep track of in your application.
If you're seeing an error when you try to insert a row without providing an id, it's likely because the id column is a primary key and cannot be undefined.