Access database using Lucid Models inside a Ace command. #2523
-
I created a custom ace for setting up a cron job on my server but when I try to access the database from the command I am getting the following error.
TestCommand.ts
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Couple of things here.
The following code should work import { BaseCommand } from '@adonisjs/ace';
export default class TestCommand extends BaseCommand {
/**
* Command Name is used to run the command
*/
public static commandName = 'test:command';
/**
* Command Name is displayed in the "help" output
*/
public static description = '';
public static settings = {
loadApp: true
}
public async run() {
const User = (await import('App/Models/User')).default
const data = await User.all();
return data;
}
} I know there are no docs around this right now and hence this can get confusing. |
Beta Was this translation helpful? Give feedback.
-
i am having this same problem with Adonis V6 can anyone help but still no luck with fixing it |
Beta Was this translation helpful? Give feedback.
Couple of things here.
settings.loadApp
option. Commands do not boot the application by default.ace-manifest.json
file.The following code should work