Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
Using console log in Knex migration not logging

My issue: The console.log('tableNobject: ', tableNobject) does not log in knex migration.
The following code is what I have tried:

// solution A
export async function up(knex: Knex) {
  const tableAobject = await knex.select('*').from('tableAobject');
  console.log('tableAobject: ', tableAobject);
}

// solution B
export async function up(knex: Knex) {
  await knex.select('*').from('tableBobject').then((tableBobject) => {
    console.log('tableBobject: ', tableBobject);
  });
}

However my terminal output is the following:

Migration Starting ...
Migrated
Migration Done.

These logs come from our migration script where we call database.migrate.latest()

My expected terminal output for the code above would be something like this:

Migration Starting ...
tableNobject: [
  {
    id: 'randomId'
    someData: 'someDataString'
    ...
  },
  ...
]
Migrated
Migration Done.

I know logging tables that you get from knex is possible because when I set up a test script outside the migration flow I can log the table without issues.

I have tried the following addition of settings:

const configA = {
  ...
  debug: true,
}

const configB = {
  ...
  log: {
    warn(message) {
      console.log(message)
    },
    error(message) {
      console.log(message)
    },
    deprecate(message) {
      console.log(message)
    },
    debug(message) {
      console.log(message)
    },
  }
}

const configC = {
  ...
  debug: true,
  log: {
    warn(message) {
      console.log(message)
    },
    error(message) {
      console.log(message)
    },
    deprecate(message) {
      console.log(message)
    },
    debug(message) {
      console.log(message)
    },
  }
};

The different settings above dont give me the logging in the terminal as I want.

The base settings (I dont know if this gives an added value):

const config = {
  client: 'postgresql',
  connection: {
    host: '127.0.0.1',
    port: '5432',
    database: 'projectName_develop',
    user: 'user',
    password: 'dev',
  },
  pool: {
    min: 2,
    max: 10,
  },
  migrations: {
    tableName: 'knex_migrations',
    directory: path.join(__dirname, 'migrations'),
  },
  seeds: {
    directory: path.join(__dirname, 'seeds'),
  },
  asyncStackTraces: true,
};
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

So the reason why my console.log didnt log was because the migrations are TypeScript files.
I forgot to run the command: npm run build-ts-backed:watch

So the solution was easier than the issue at hand. Please remember to run your TypeScript compiler when you test in TypeScript.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!