migrate:make foo results in "calling knex without a tableName is deprecated. Use knex.queryBuilder() instead.
See original GitHub issueEnvironment
Knex version: 0.21.0 Database + version: PostgreSQL 12.2 (docker) OS: Ubuntu 19.10
Bug
- Explain what kind of behaviour you are getting and how you think it should do
When trying to create migration with:
npx knex --knexfile ./src/db/knexfile.js migrate:make foobar
knex
complains about:
calling knex without a tableName is deprecated. Use knex.queryBuilder() instead.
The same happens when I try seed:make foobar
but I’m able to run queries against the db.
I’m using node
experimental esm support via "type": "module"
. To keep knex
happy I’m employing “a non-module package.json” as described by @D10221 in this comment.
- Error message
Working directory changed to ~/code/playground/moviedb/src/db
calling knex without a tableName is deprecated. Use knex.queryBuilder() instead.
(node:18834) UnhandledPromiseRejectionWarning: error: select * - SELECT * with no tables specified is not valid
at Connection.parseE (/home/boojum/code/playground/moviedb/node_modules/pg/lib/connection.js:600:48)
at Connection.parseMessage (/home/boojum/code/playground/moviedb/node_modules/pg/lib/connection.js:399:19)
at Socket.<anonymous> (/home/boojum/code/playground/moviedb/node_modules/pg/lib/connection.js:115:22)
at Socket.emit (events.js:315:20)
at addChunk (_stream_readable.js:297:12)
at readableAddChunk (_stream_readable.js:273:9)
at Socket.Readable.push (_stream_readable.js:214:10)
at TCP.onStreamRead (internal/stream_base_commons.js:186:23)
(node:18834) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:18834) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
- Reduced test code, for example in https://npm.runkit.com/knex or if it needs real database connection to MySQL or PostgreSQL, then single file example which initializes needed data and demonstrates the problem.
Repo with toy code demonstrating the isse can be found on gitlab. I’m betting on issue being with knexfile
which can be seen below:
const dotenv = require("dotenv").config({ path: __dirname + "/../../.env" });
const knex = require("knex");
const config = {
development: {
client: "pg",
connection: {
host: process.env.POSTGRES_HOST,
port: process.env.POSTGRES_PORT,
user: process.env.POSTGRES_USER,
password: process.env.POSTGRES_PASSWORD,
database: process.env.POSTGRES_DB,
},
migrations: {
tableName: "knex_migrations",
directory: "./migrations",
},
seeds: { directory: "./seeds" },
},
};
const db = knex(config[`${process.env.NODE_ENV}`]);
module.exports = knex(config[`${process.env.NODE_ENV}`]);
module.exports = db;
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
mysql - Knex.js query throws warning "Calling knex without a ...
Knex :warning - calling knex without a tableName is deprecated. Use knex.queryBuilder() instead. Please review following error and my codes.
Read more >Knex Query Builder
The query builder starts off either by specifying a tableName you wish to query against, or by calling any method directly on the...
Read more >Test Driven Development with Node, Postgres, and Knex (Red ...
Knex is a SQL query builder that we can use with PostgreSQL to handle migrations, ... Deletes ALL existing entries knex('table_name').del(), ...
Read more >Knex cheatsheet - Devhints
One-page guide to Knex: usage, examples, and more. Knex is an SQL query builder for Node.js.This guide targets v0.13.0.
Read more >Other Methods | Objection.js - GitHub Pages
toKnexQuery(). knexQueryBuilder = queryBuilder.toKnexQuery();. Compiles the query into a knex query and returns the knex query builder instance.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It seems to me the problem is here
‘module.exports’ is ‘Knex Function’, instead of “Knex’s Config”
I think… you could share your ‘knex’ configuration between the ‘migrations’ and the app code. instead of the Knex instance
Thanks @D10221
knexfile.js
database.js
and at file_to_access_data.js