简体   繁体   中英

How to fix Unhandled rejection SequelizeConnectionError: No Database selected

I am using ORM and i am in new in this. I searched alot but nothing found. Please help me to figure out the error

Here is the error

在此处输入图片说明

And Here is the Database connection

const Sequelize = require("sequelize");
const config = require("../../config/config.json");

const sequelize = new Sequelize(
  config.database,
  config.username,
  config.password,
  {
    host: "127.0.0.1",
    port: "80",
    dialect: "mysql",
    operatorAliases: false
  }
);

module.exports = sequelize;
global.sequelize = sequelize;

Here is the Model

const Sequelize = require("sequelize");

module.exports = sequelize.define("users", {
  id: {
    type: Sequelize.INTEGER(11),
    allowNull: false,
    autoIncrement: true,
    primaryKey: true
  },
  name: {
    type: Sequelize.STRING,
    allowNull: false
  },
  email: {
    type: Sequelize.STRING,
    allowNull: false,
    unique: true
  },
  password: {
    type: Sequelize.STRING,
    allowNull: false
  }
});

Below is the Query

var express = require("express");
var router = express.Router();
var users = require("../src/models/Users");
/* GET home page. */
router.get("/", function(req, res, next) {
  users.findAll({
    where: {
      id: 1
    }
  });
});

module.exports = router;

Any solution appreciated!

I think the problem isn't with the ORM, instead it is a problem with your connection details.

On what port does your mysql instance running on? Try the default mysql port: 3306 .

Also, try to test the connection to this port using the command telnet 127.0.0.1 PORT (replace PORT with the port that your mysql instance is running on)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM