Invalid Month error on table.timestamps() - Reposting
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:
What happens if you change the precision of timestamps to 4. table.timestamps(4)?
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')
}
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
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"
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
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"
Okay, gonna try it myself with the actual oracle server
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
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.