I'm attempting to insert a new record with a JSONB field type included.
Below is the structure I am trying to create, along with the error message I am receiving.
The specific field causing the issue is "veiculo"
The ORM is struggling to access the nested values within the JSON for identification.
It should be inserting the entire object as it is.
Thank you for your attention and assistance.
Post
{
veiculo: {
placa: 'PLACA',
motorista: 'NOME',
contato: 'CONTATO',
casa: true,
horaEntrada: '2022-01-20T05:02:22.000Z'
},
fornecedor: 'ALIMENTOS',
lab: 'sim',
}
Model
import { DateTime } from 'luxon'
import { BaseModel, column } from '@ioc:Adonis/Lucid/Orm'
export default class Produto extends BaseModel {
@column({ isPrimary: true })
public id: number
@column()
public fornecedor: string
@column()
public lab: string
@column()
public veiculo: Object
@column.dateTime({ autoCreate: true })
public createdAt: DateTime
@column.dateTime({ autoCreate: true, autoUpdate: true })
public updatedAt: DateTime
Migration
public async up () {
this.schema.createTable(this.tableName, (table) => {
table.increments('id')
table.string('fornecedor')
table.string('lab')
table.jsonb('veiculo')
/**
* Uses timestamptz for PostgreSQL and DATETIME2 for MSSQL
*/
table.timestamp('created_at', { useTz: true })
table.timestamp('updated_at', { useTz: true })
})
}
Error
Error: ER_BAD_FIELD_ERROR: Unknown column 'placa' in 'field list'