Nisha Patel
Problem
I'm using Sequelize with Typescript and looking for a way to run Course.create() but can't avoid needing to specify an id field just to run the .create() method. Here is the Course model:
Note that I would like to pass in this data without the id. I don't want to have to include an id when I make a POST request. But no matter what I do, I always seem to get an error Error: Field 'id' doesn't have a default value.
How can I solve this?
Solution
It seems that you'll need to do two things:
specify a defaultValue key on the model.
use a separate package (or custom function) to generate the UUID for defaultValue.
The following code example is inspired by >issue 13912 on the Sequelize Github repo..
import { Uuid4 } from 'id128'
Suggested blogs:
>How to Select checkboxes on an HTML treeview with JavaScript?
>How to use querySelectorAll()" with multiple conditions in JavaScript?
>How to fix mouseover event glitch in JavaScript?
>How to do light and dark mode in a website using HTML and JavaScript?
>How to manipulate manipulating Array object in JavaScript?
>How to merge an object into Array with the same key in JavaScript?
>Javascript Error Solved: Property 'id' does not exist on type 'T'
>Why highlighted table row using class not working in JavaScript?
>How to rename an object key based on the condition in JavaScript?
>How to sort an array based on another array in Javascript?
>Javascript: Modal not closing with a button