Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set a default value using enum type in column Mysql using Knex.js?

I am using AdonisJS to make a backend application. In migrations, specifically in models, we have the option of creating models, but I can't use a default value in enun type. After reading the Knex.js documentation, I couldn't find a way to put this default value in enum type (table.enu) in SGDB Mysql. Could anyone help?

https://adonisjs.com/docs/4.1/migrations

http://knexjs.org/#Schema-enum

like image 571
Taffarel Xavier Avatar asked Dec 23 '22 21:12

Taffarel Xavier


1 Answers

Did you try defaultTo() :

defaultTo — column.defaultTo(value)

Sets the default value for the column on an insert.

From knex Documentation

Example :

table.enu('role', ['one', 'two', 'three']).defaultTo('two', options={})

Adonis Enu/Enum documentation

Adonis defaultTo documentation

like image 88
crbast Avatar answered Dec 25 '22 11:12

crbast