UPSERT and autogenerated ID (primary key)

I have an HTML form with 3 rows.
I have 2 saved records in the table (user didn't fill in all)

The next time the user logs in, he continues to fill out the form, which is pre filled with the previous 2 records from the db.
  • He edits one row
  • Fills in the last row, and submits.
How can I:
  • save the new row,
  • update the edited one
  • ignore the unedited row
    ...without adding duplicates
I tried this:
await supabase
.from('notes')
.insert([
        {
            text: 'This is a test',
            user_id: '123',
            form_row: 1,
        },
        {
            text: 'This is another test',
            user_id: '123',
            form_row: 3,
        },
    ],
    { 
        upsert: true, 
        onConflict: 'id', 
        ignoreDuplicates: false 
    })
.select()

but get this error :
null value in column "id" of relation "notes" violates not-null constraint

id
is auto increment

Can I use UPSERT this way?
Was this page helpful?