最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

Node Mysql序列化'ERR

IT培训 admin 11浏览 0评论

Node Mysql序列化'ERR

所以当我尝试运行该项目时,出现上述错误。我只是创建2个表,然后运行serialize.sync()。我对Node,MySQL和Serielize都是新手,所以我完全不知道为什么会这样。另外,如果您想在这里看到更多内容,请访问github项目:blog_books_dev删除mysql cli并再次运行,无论数据库是否存在,它都会给出相同的错误。这是错误的样子:

[nodemon] restarting due to changes...
[nodemon] starting `node index.js`
server is running on port 3001
tedious deprecated The default value for `config.options.trustServerCertificate` will change from `true` to `false` in the next major version of `tedious`. Set the value to `true` or `false` explicitly to silence this message. node_modules/sequelize/lib/dialects/mssql/connection-manager.js:63:26
tedious deprecated In the next major version of `tedious`, creating a new `Connection` instance will no longer establish a connection to the server automatically. Please use the new `connect` helper function or call the `.connect` method on the newly created `Connection` object to silence this message. internal/process/task_queues.js:79:11
internal/buffer.js:75
    throw new ERR_BUFFER_OUT_OF_BOUNDS();
    ^

RangeError [ERR_BUFFER_OUT_OF_BOUNDS]: Attempt to access memory outside buffer bounds
    at boundsError (internal/buffer.js:75:11)
    at Buffer.readUInt8 (internal/buffer.js:243:5)
    at Packet.type (/home/emil/emil/projects/blogBooks/node_modules/tedious/lib/packet.js:143:24)
    at IncomingMessageStream.processBufferedData (/home/emil/emil/projects/blogBooks/node_modules/tedious/lib/incoming-message-stream.js:72:26)
    at IncomingMessageStream._transform (/home/emil/emil/projects/blogBooks/node_modules/tedious/lib/incoming-message-stream.js:107:10)
    at IncomingMessageStream.Transform._read (/home/emil/emil/projects/blogBooks/node_modules/tedious/node_modules/readable-stream/lib/_stream_transform.js:177:10)
    at IncomingMessageStream.Transform._write (/home/emil/emil/projects/blogBooks/node_modules/tedious/node_modules/readable-stream/lib/_stream_transform.js:164:83)
    at doWrite (/home/emil/emil/projects/blogBooks/node_modules/tedious/node_modules/readable-stream/lib/_stream_writable.js:409:139)
    at writeOrBuffer (/home/emil/emil/projects/blogBooks/node_modules/tedious/node_modules/readable-stream/lib/_stream_writable.js:398:5)
    at IncomingMessageStream.Writable.write (/home/emil/emil/projects/blogBooks/node_modules/tedious/node_modules/readable-stream/lib/_stream_writable.js:307:11)
    at Socket.ondata (_stream_readable.js:708: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) {
  code: 'ERR_BUFFER_OUT_OF_BOUNDS'
}
[nodemon] app crashed - waiting for file changes before starting...

这里是数据库代码:

const Sequelize = require('sequelize')
const User = require('./models/user')
const Blog = require('./models/blog')
const logger = require('../utils/logger')
const dbConfigs = require('./config')

let sequelize
if (process.env.NODE_ENV === 'production') {
    sequelize = new Sequelize(dbConfigs.production)
} else if (process.env.NODE_ENV === 'development') {
    sequelize = new Sequelize(dbConfigs.development)
} else if (process.env.NODE_ENV === 'test') {
    sequelize = new Sequelize(dbConfigs.test)
} else {
    logger.error('error when connecting to db, invalid or empty NODE_ENV')
    // throw something ..?
}

const userModel = sequelize.define('user', User)
const blogModel = sequelize.define('blog', Blog)
userModel.hasMany(blogModel)
blogModel.belongsTo(userModel)

module.exports = {
    sequelize,
    User: userModel,
    Blog: blogModel,
}

用户模型代码:

const Sequelize = require('sequelize')

module.exports = {
    id: {
        type: Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true,
    },
    username: {
        type: Sequelize.STRING,
        allowNull: false,
        unique: true,
        validate: {
            len: [5, 20],
        },
    },
    name: Sequelize.STRING,
    passwordHash: {
        type: Sequelize.STRING,
        allowNull: false,
    },
    isAdmin: {
        type: Sequelize.BOOLEAN,
        defaultValue: false,
    },
}

博客模型代码:

const Sequelize = require('sequelize')

module.exports = {
    id: {
        type: Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true,
    },
    title: {
        type: Sequelize.STRING,
        AllowNull: false,
        validate: {
            len: [5, 20],
        },
    },
    content: {
        type: Sequelize.STRING,
        AllowNull: false,
        validate: {
            len: [20, 500],
        },
    },
    date: {
        type: Sequelize.DATE,
        defaultValue: Sequelize.NOW,
    },
}

以及新Serialize(options)的选项(我删除了密码,因为它是所有内容的主要密码,我为irl):

const production = 'link to production db'

const development = {
    host: 'localhost',
    database: 'blog_books_dev',
    username: 'root',
    password: '',
    dialect: 'mssql',
    // open mysql command line and type SHOW GLOBAL VARIABLES LIKE 'PORT';
    // to see waht port mysql is running on
    port: '3306',
}

const test = {
    host: 'localhost',
    database: 'blog_books_test',
    username: 'root',
    password: '',
    dialect: 'mssql',
    port: '3306',
}

module.exports = { production, development, test }
回答如下:

我写了mssql而不是mysql

const development = {
    host: 'localhost',
    database: 'blog_books_dev',
    username: 'root',
    password: '',
    dialect: 'mssql',
    // open mysql command line and type SHOW GLOBAL VARIABLES LIKE 'PORT';
    // to see waht port mysql is running on
    port: '3306',
}

应该是:

const development = {
    host: 'localhost',
    database: 'blog_books_dev',
    username: 'root',
    password: '',
    dialect: 'mysql', // THIS WAS THE PROBLEM
    // open mysql command line and type SHOW GLOBAL VARIABLES LIKE 'PORT';
    // to see waht port mysql is running on
    port: '3306',
}

Node Mysql序列化'ERR

所以当我尝试运行该项目时,出现上述错误。我只是创建2个表,然后运行serialize.sync()。我对Node,MySQL和Serielize都是新手,所以我完全不知道为什么会这样。另外,如果您想在这里看到更多内容,请访问github项目:blog_books_dev删除mysql cli并再次运行,无论数据库是否存在,它都会给出相同的错误。这是错误的样子:

[nodemon] restarting due to changes...
[nodemon] starting `node index.js`
server is running on port 3001
tedious deprecated The default value for `config.options.trustServerCertificate` will change from `true` to `false` in the next major version of `tedious`. Set the value to `true` or `false` explicitly to silence this message. node_modules/sequelize/lib/dialects/mssql/connection-manager.js:63:26
tedious deprecated In the next major version of `tedious`, creating a new `Connection` instance will no longer establish a connection to the server automatically. Please use the new `connect` helper function or call the `.connect` method on the newly created `Connection` object to silence this message. internal/process/task_queues.js:79:11
internal/buffer.js:75
    throw new ERR_BUFFER_OUT_OF_BOUNDS();
    ^

RangeError [ERR_BUFFER_OUT_OF_BOUNDS]: Attempt to access memory outside buffer bounds
    at boundsError (internal/buffer.js:75:11)
    at Buffer.readUInt8 (internal/buffer.js:243:5)
    at Packet.type (/home/emil/emil/projects/blogBooks/node_modules/tedious/lib/packet.js:143:24)
    at IncomingMessageStream.processBufferedData (/home/emil/emil/projects/blogBooks/node_modules/tedious/lib/incoming-message-stream.js:72:26)
    at IncomingMessageStream._transform (/home/emil/emil/projects/blogBooks/node_modules/tedious/lib/incoming-message-stream.js:107:10)
    at IncomingMessageStream.Transform._read (/home/emil/emil/projects/blogBooks/node_modules/tedious/node_modules/readable-stream/lib/_stream_transform.js:177:10)
    at IncomingMessageStream.Transform._write (/home/emil/emil/projects/blogBooks/node_modules/tedious/node_modules/readable-stream/lib/_stream_transform.js:164:83)
    at doWrite (/home/emil/emil/projects/blogBooks/node_modules/tedious/node_modules/readable-stream/lib/_stream_writable.js:409:139)
    at writeOrBuffer (/home/emil/emil/projects/blogBooks/node_modules/tedious/node_modules/readable-stream/lib/_stream_writable.js:398:5)
    at IncomingMessageStream.Writable.write (/home/emil/emil/projects/blogBooks/node_modules/tedious/node_modules/readable-stream/lib/_stream_writable.js:307:11)
    at Socket.ondata (_stream_readable.js:708: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) {
  code: 'ERR_BUFFER_OUT_OF_BOUNDS'
}
[nodemon] app crashed - waiting for file changes before starting...

这里是数据库代码:

const Sequelize = require('sequelize')
const User = require('./models/user')
const Blog = require('./models/blog')
const logger = require('../utils/logger')
const dbConfigs = require('./config')

let sequelize
if (process.env.NODE_ENV === 'production') {
    sequelize = new Sequelize(dbConfigs.production)
} else if (process.env.NODE_ENV === 'development') {
    sequelize = new Sequelize(dbConfigs.development)
} else if (process.env.NODE_ENV === 'test') {
    sequelize = new Sequelize(dbConfigs.test)
} else {
    logger.error('error when connecting to db, invalid or empty NODE_ENV')
    // throw something ..?
}

const userModel = sequelize.define('user', User)
const blogModel = sequelize.define('blog', Blog)
userModel.hasMany(blogModel)
blogModel.belongsTo(userModel)

module.exports = {
    sequelize,
    User: userModel,
    Blog: blogModel,
}

用户模型代码:

const Sequelize = require('sequelize')

module.exports = {
    id: {
        type: Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true,
    },
    username: {
        type: Sequelize.STRING,
        allowNull: false,
        unique: true,
        validate: {
            len: [5, 20],
        },
    },
    name: Sequelize.STRING,
    passwordHash: {
        type: Sequelize.STRING,
        allowNull: false,
    },
    isAdmin: {
        type: Sequelize.BOOLEAN,
        defaultValue: false,
    },
}

博客模型代码:

const Sequelize = require('sequelize')

module.exports = {
    id: {
        type: Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true,
    },
    title: {
        type: Sequelize.STRING,
        AllowNull: false,
        validate: {
            len: [5, 20],
        },
    },
    content: {
        type: Sequelize.STRING,
        AllowNull: false,
        validate: {
            len: [20, 500],
        },
    },
    date: {
        type: Sequelize.DATE,
        defaultValue: Sequelize.NOW,
    },
}

以及新Serialize(options)的选项(我删除了密码,因为它是所有内容的主要密码,我为irl):

const production = 'link to production db'

const development = {
    host: 'localhost',
    database: 'blog_books_dev',
    username: 'root',
    password: '',
    dialect: 'mssql',
    // open mysql command line and type SHOW GLOBAL VARIABLES LIKE 'PORT';
    // to see waht port mysql is running on
    port: '3306',
}

const test = {
    host: 'localhost',
    database: 'blog_books_test',
    username: 'root',
    password: '',
    dialect: 'mssql',
    port: '3306',
}

module.exports = { production, development, test }
回答如下:

我写了mssql而不是mysql

const development = {
    host: 'localhost',
    database: 'blog_books_dev',
    username: 'root',
    password: '',
    dialect: 'mssql',
    // open mysql command line and type SHOW GLOBAL VARIABLES LIKE 'PORT';
    // to see waht port mysql is running on
    port: '3306',
}

应该是:

const development = {
    host: 'localhost',
    database: 'blog_books_dev',
    username: 'root',
    password: '',
    dialect: 'mysql', // THIS WAS THE PROBLEM
    // open mysql command line and type SHOW GLOBAL VARIABLES LIKE 'PORT';
    // to see waht port mysql is running on
    port: '3306',
}

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论