Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
Insert record in mysql with adonisjs jsonb field

I'm trying to insert a record where one of the fields is of type JSONB

Below is the format I'm trying to build and at the end the error that is being issued.

The field in question is veiculo

orm is trying to access the inside of the json to try to indetify the field.

It should insert the complete object.

I thank the attention. Thanks.

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'

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Resolved with await dataNfe.related('items').createMany(items)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!