Sample Header Ad - 728x90

''No database selected'' error in Render

1 vote
0 answers
98 views
I created a project on Node js(Express js) with sequelize ORM and earlier, I used sequelize-cli to create and migrate database and tables respectively. this is my package.json: { "name": "library-management", "version": "0.0.0", "private": true, "scripts": { "start": "nodemon app.js", "install-and-migrate": "npm install && sequelize-cli db:create && sequelize-cli db:migrate" }, "dependencies": { "bcrypt": "^5.1.1", "dotenv": "^16.3.1", "express": "^4.18.2", "jsonwebtoken": "^9.0.2", "nodemon": "^3.0.1", "sequelize": "^6.32.1", "sequelize-cli": "^6.6.1" }, "devDependencies": { "mysql2": "^3.6.0" } } and this is my config.js file after changing it from config.json: const dotenv = require('dotenv'); dotenv.config(); const config = { dialect: process.env.DB_DIALECT || "mysql", host: process.env.DB_HOST || "127.0.0.1", port: process.env.DB_PORT || 3306, username: process.env.DB_USERNAME || "root", password: process.env.DB_PASSWORD, }; // console.log(config); module.exports = { url: process.env.DB_CONNECTION_URL, development: { ...config, database: process.env.DB_DEVELOPMENT_NAME }, test: { ...config, database: process.env.DB_TEST_NAME }, production: { ...config, database: process.env.DB_PROD_NAME }, }; and .sequelizerc: const path = require('path'); module.exports = { 'config': path.resolve('config', 'config.js'), 'models-path': path.resolve('models'), // 'seeders-path': path.resolve('seeders'), 'migrations-path': path.resolve('migrations') }; and my app.js: require('dotenv').config(); const express = require('express'); const app = express() const userRoutes = require("./routes/userRoutes") const adminRoutes = require("./routes/adminRoutes") const bookRoutes = require("./routes/bookRoutes") const authorRoutes = require("./routes/authorRoutes") app.use(express.json()) app.use('/users',userRoutes) app.use('/book',bookRoutes) app.use('/author',authorRoutes) app.use('/admin',adminRoutes) app.listen(3000); When I started the deployment operation, it showed me that: Nov 23 10:46:38 AM Sequelize CLI [Node: 14.17.0, CLI: 6.6.2, ORM: 6.35.1] Nov 23 10:46:38 AM Nov 23 10:46:38 AM Loaded configuration file "config/config.js". Nov 23 10:46:38 AM Using environment "development". Nov 23 10:46:41 AM Database bzkjl4pacusbj3w7ymkv created. Nov 23 10:46:41 AM Nov 23 10:46:41 AM Sequelize CLI [Node: 14.17.0, CLI: 6.6.2, ORM: 6.35.1] Nov 23 10:46:41 AM Nov 23 10:46:41 AM Loaded configuration file "config/config.js". Nov 23 10:46:41 AM Using environment "development". Nov 23 10:46:44 AM No migrations were executed, database schema was already up to date. But when I started inserting the endpoints using PostMan, it's telling me that: Nov 23 12:43:37 PM original: Error: No database selected Nov 23 12:43:37 PM at Packet.asError (/opt/render/project/src/Server/node_modules/mysql2/lib/packets/packet.js:728:17) Nov 23 12:43:37 PM at Query.execute (/opt/render/project/src/Server/node_modules/mysql2/lib/commands/command.js:29:26) Nov 23 12:43:37 PM at Connection.handlePacket (/opt/render/project/src/Server/node_modules/mysql2/lib/connection.js:478:34) Nov 23 12:43:37 PM at PacketParser.onPacket (/opt/render/project/src/Server/node_modules/mysql2/lib/connection.js:97:12) Nov 23 12:43:37 PM at PacketParser.executeStart (/opt/render/project/src/Server/node_modules/mysql2/lib/packet_parser.js:75:16) Nov 23 12:43:37 PM at Socket. (/opt/render/project/src/Server/node_modules/mysql2/lib/connection.js:104:25) Nov 23 12:43:37 PM at Socket.emit (events.js:376:20) Nov 23 12:43:37 PM at addChunk (internal/streams/readable.js:309:12) Nov 23 12:43:37 PM at readableAddChunk (internal/streams/readable.js:284:9) Nov 23 12:43:37 PM at Socket.Readable.push (internal/streams/readable.js:223:10) { Nov 23 12:43:37 PM code: 'ER_NO_DB_ERROR', Nov 23 12:43:37 PM errno: 1046, Nov 23 12:43:37 PM sqlState: '3D000', Nov 23 12:43:37 PM sqlMessage: 'No database selected', Nov 23 12:43:37 PM sql: 'SELECT id, first_name, last_name, role, username, email, password, age, createdAt, updatedAt FROM Users AS User;', Nov 23 12:43:37 PM parameters: undefined Nov 23 12:43:37 PM }, Nov 23 12:43:37 PM sql: 'SELECT id, first_name, last_name, role, username, email, password, age, createdAt, updatedAt FROM Users AS User;', Nov 23 12:43:37 PM parameters: {} Nov 23 12:43:37 PM } I have shared my concerns in their community room but I still cannot figure out whether is this happening from my side or from theirs. because its still working in the localhost. I am using cleaver-cloud to create a mysql add-on so that I can create a live database.
Asked by suborno das (11 rep)
Nov 23, 2023, 07:23 AM