New record with custom created_at using Lucid models?


Is it possible to create a record with different created_at then current time?

I’m writing parse script, and I need to import old records to new database. I want to keep created_at and updated_at fields as they were on the old database.

By using:

AnyModel.create({whatever: 123, created_at: _CUSTOM DATE HERE_})

I’m always getting created_at date set to current time.


You can set createdAtColumn to null to avoid the automagic setting.


Yeah, but I want this behaviour. I just want to turn it off briefly until parsing of old database is done.

After it, I want to auto generate dates for all new records.


Well, it’s just JS … you can temporarily extend a Model class and use it and then discard it…


You are right… Thats the way to go… I searched for some “adonis” way of doing this, but this will do