Search code examples
javascriptdefault-valueknex.js

What does the knex.js method `table.increments()` do when no args are passed in?


I'm working on a codebase and I see a few migrations that invoke table.increments() when restoring a table inside a knex.schema.createTable() call. Looking at the documentation for this method, it appears to add an auto-incrementing column with the given name. However, in my case it's being called without any arguments. Is there some kind of default parameter that's being used for name? Or is table.increments() just not doing anything here?


Solution

  • It uses the name id for the column by default if none is specified. Here's the code where this behavior is defined.

    It's unfortunate this is not documented, perhaps an issue could be opened up in their GitHub page to bring this to the attention of the knex team.