Er_wrong_value_count_on_row


#1

Hi,

Code of the controller :

async store({request, response, auth}) {
        const user = await auth.getUser()

        // validate form input
        const validation = await Validator.validateAll(request.all(), {
            title: 'required',
            category: 'required',
            priority: 'required',
            message: 'required'
        })

        if (validation.fails()) {
            await request.withAll().andWith({ errors: validation.messages() }).flash()
  
            return response.redirect('back')
        }

        const ticket = await Ticket.create({
            title: request.input('title'),
            user_id: user.id,
            category_id: request.input('category'),
            priority: request.input('priority'),
            message: request.input('message'),
            status: "Open",
        })


        response.redirect('back')
    }

And the migration:

  up () {
    this.create('tickets', (table) => {
      table.increments()
      table.integer('user_id').unsigned()
      table.integer('category_id').unsigned()
      table.string('title')
      table.string('priority')
      table.text('message')
      table.string('status')
      table.timestamps()
    })
  }

The problem occurs when sending the form, the migration does not occur, here is the error : ER_WRONG_VALUE_COUNT_ON_ROW: Column count doesn't match value count at row 1

Thanks for your help.


#2

your table columns doesnt match with your migration file

I mean your const ticket has a different order from your up method into your migration file


#3

No, I have the same order in const ticket and in the migration file


#4

Actually the order of fields do not affect the query, the core will do the magic.
Have you look at the table you have create? Does it have the exact fields in your migration file?
Since most of the people have create the table while they still trying on the migration file and the table is not in the final structure when they start coding.