core icon indicating copy to clipboard operation
core copied to clipboard

Invalid Month error on table.timestamps() - Reposting

Open malepatip opened this issue 8 years ago • 9 comments

Hello, I am reposting this question as i dont see much views on my question on forum.adonisjs.com I am using Oracle database for posting data from HTML Page. All my models, migrations, views, are defaults to Adonis 4.1 documentation, not customized anything.

Migration:

up () {
    this.create('ois', (table) => {
      table.increments()
      table.string('proj_name').notNullable()  
      table.timestamps()
    })
  }

Model:

'use strict'
const Model = use('Model')

class Oi extends Model {
}

module.exports = Oi

Controller:

async store({ request, response, session }){
     //persist to database
    const oi = new Oi()
    oi.proj_name = request.input('Projname')
    await oi.save()
    return response.redirect('/oi')

I get this error, after filling the form:

Error

insert into “ois” (“created_at”, “proj_name”, “updated_at”) values (:1, :2, :3) returning “id” into :4 - ORA-01843: not a valid month

Database Table Structure: capture3

malepatip avatar Jul 23 '18 15:07 malepatip

What happens if you change the precision of timestamps to 4. table.timestamps(4)?

thetutlage avatar Jul 25 '18 07:07 thetutlage

I treid that, throwing same error, but I was able get through .insert function, here is the code:

async store({request, response}) {
    await Database
    .insert({
        created_at: Database.raw("CURRENT_TIMESTAMP"),
        proj_name: request.input('proj_name'), 
        updated_at: Database.raw("CURRENT_TIMESTAMP")
    })
    .into ('ois')
    return response.redirect('/oi')    
}

malepatip avatar Jul 26 '18 20:07 malepatip

So you are using the Database query builder directly and not Lucid models?

Also can you share the version of @adonisjs/lucid in your package.json file

thetutlage avatar Jul 27 '18 05:07 thetutlage

Well, first I used models and I got invalid month error, so as a workaround I had to skip Lucid Models and using Database query builder directly.

@adonisjs/lucid": "^5.0.4"

malepatip avatar Jul 27 '18 14:07 malepatip

Can you upgrade to the most recent version of Lucid, which is 6.0.x and lemme if problem persists.

I don't deal with oracle everyday, but if problem still persists, I will try it manually on Oracle and see what's causing this

thetutlage avatar Jul 29 '18 06:07 thetutlage

Ok, Not sure if I did the update of lucid to 6.0.x to correctly, this is what I see in my package.json:

"@adonisjs/lucid": "git+https://github.com/adonisjs/adonis-lucid.git",

After installing the latest lucid (which I am thinking), I still get the same error "Invalid Month"

malepatip avatar Jul 31 '18 15:07 malepatip

Okay, gonna try it myself with the actual oracle server

thetutlage avatar Aug 01 '18 04:08 thetutlage

Hi all, I was able to resolve this using the following code:

const moment = require('moment')
...

static formatDates (field, value) {

  return moment(value).toDate()
}

I used momentjs npm library in case you are not familiar. This error occurs because oracle db cannot recognize the default format.

Just put this piece of code into your Lucid model. This is a type of mutator, the setter.

I'm using Adonis 4.1

jaybeemind avatar Oct 26 '18 06:10 jaybeemind

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Mar 10 '20 20:03 lock[bot]