node.js - 如何修复未处理的拒绝 SequelizeConnectionError : No Database selected

标签 node.js sequelize.js

我正在使用 ORM,我是新手。我搜索了很多,但没有找到。请帮我找出错误
这是错误
enter image description here
这是数据库连接

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;

这是模型
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
  }
});

下面是查询
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;

任何解决方案表示赞赏!

最佳答案

我认为问题不在于 ORM,而在于您的连接详细信息。

您的 mysql 实例在哪个端口上运行?
尝试默认的 mysql 端口: 3306

另外,尝试使用命令 telnet 127.0.0.1 PORT 测试与此端口的连接
(将 PORT 替换为您的 mysql 实例运行所在的端口)

关于node.js - 如何修复未处理的拒绝 SequelizeConnectionError : No Database selected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60017676/

相关文章:

node.js - Node.js 是否内置了对 UDP(datagams) 的支持?

node.js - Xero SDK - 状态参数的OAuth实现

node.js - 无法使用node.js与facebook的图形API交互

sequelize.js 迁移执行顺序

node.js - Sequelize - 需要一个没有对应表列的属性

Node.js sequelize 关联包括

mysql - 如何从 Nodejs Mysql 获取 JSON 类型作为 JSON 而不是 String

javascript - 使用 CryptoJS 将解密格式解析为具有大部分填充的字符串时出现问题

javascript - 如何进行 Sequelize 更新以返回更新后的对象?

mariadb - 如何使用 sequelize 删除行