Create new records in the database
create()
method creates a new record in the database and returns the model instance. It’s the most common way to insert new data.
Parameter | Type | Required | Description |
---|---|---|---|
attributes | Object | Yes | Data to insert into the database |
options | Object | No | Additional options for creation |
Option | Type | Default | Description |
---|---|---|---|
connection | string | null | Database connection to use |
returning | Array|string | ['*'] | Columns to return after insert |
onConflict | string | null | Conflict resolution strategy |
Promise<Model>
Model.make()
- Create model instance without savingModel.firstOrCreate()
- Find existing or create newModel.updateOrCreate()
- Update existing or create newModel.insertMany()
- Create multiple records