Tag: sequelize cli

Node.js中的模型文件不会考虑configuration

我有这样的模型文件,如下所示: 'use strict' module.exports = function (sequelize, DataTypes) { let User = sequelize.define('user', { id: { type: DataTypes.INTEGER(11), allowNull: false, primaryKey: true, autoIncrement: true } }, { classMethods: { associate: function(models) { this.belongsToMany(models.role, { through: { model: 'user_role' }, foreignKey: 'user_id' }) } } }, { tableName: 'user', timestamps: false, underscored: true } ) return […]

为多个关系表添加js orm播种器

我将这样sequelize种子初始数据加载邮政。我可以通过创buildseedfile.js.能够做到多表,但我无法处理表之间的关系自动。 // user_seeds.js up: function (queryInterface, Sequelize) { return queryInterface.bulkInsert(table, [{ uid: 1, //primary key autogenerated name: 'John doe', email: 'john@doe.com', created_at, updated_at }], {}); // roles_seeds.js up: function (queryInterface, Sequelize) { return queryInterface.bulkInsert(table, [{ uid: 1, //this should be comes from user table to this filed automatically after the creation of first record in […]

使用Sequelize mysql更新批量数据

我想更新超过10万的数据,但我无法更新它。 我正在使用Sequalize和MySQL。 我首先从.txt文件中读取数据,然后根据表中已有的数据更新表格数据。 我正在使用Sequalize,但需要1个多小时才能更新100k条logging。 有没有办法使用Sequalize更新批量数据? 这是我的示例代码: async.each(arrayData, function(_arrayData, _callback) { var connection = index.connection; let query = 'UPDATE debit_tran_reg SET response_status ='+'"'+_arrayData.response_status+'"'+',response_rejection_reason='+'"'+_arrayData.response_rejection_reason+'"'+',umrn_no='+'"'+_arrayData.umrn_no+'"'+'WHERE loan_no ='+'"'+_arrayData.loan_no+'"'+''; connection.query(query).spread((results, metadata) => { console.log("results> "+JSON.stringify(results)); }); _callback(); },function(err){ if(err){ console.log(err); }else{ console.log("*****ALL DATA HAS BEEN PROCESSED*****") } });

Postgres和Sequelize – 无法读取未定义的属性“名称”

我正在尝试在一个正在MySQL上运行良好的项目更改数据库到Postgres。 运行迁移时(收到sync和sequelize db:migrate),我收到以下错误消息。 /myProject/node_modules/pg/lib/connection.js:109 self.emit(msg.name, msg); ^ TypeError: Cannot read property 'name' of undefined at Socket.<anonymous> (/myProject/node_modules/pg/lib/connection.js:109:20) at emitOne (events.js:96:13) at Socket.emit (events.js:188:7) at readableAddChunk (_stream_readable.js:172:18) at Socket.Readable.push (_stream_readable.js:130:10) at TCP.onread (net.js:542:20) 我只隔离了这个简单的模型,但是我仍然得到错误 module.exports = (sequelize, DataTypes) => { var User = sequelize.define('User', { email: { type: DataTypes.STRING, validate: { isEmail: true } }, googleId: […]

Message.Create不是一个函数会话cli

我已经在我的项目中安装了mysql sequelize然后我使用sequelize命令创build模型和迁移文件creadted消息模型。我也给了在config.json文件中的数据库凭据。现在我试图在我的数据库插入logging,但得到这个错误在这里是我的模型文件 我需要明确地build立数据库连接,或者它会自动从config.json文件中select证书来build立连接? 车型/ messages.js 'use strict'; module.exports = (sequelize, DataTypes) => { var Messages = sequelize.define('Messages', { room: DataTypes.STRING, nickname: DataTypes.STRING, message: DataTypes.STRING, receiver: DataTypes.STRING }, { classMethods: { associate: function(models) { // associations can be defined here } } }); return Messages; }; 这里是config.json文件config / config.json { "development": { "username": "root", "password": "asad", […]

我使用Sequelize的数据库模型不做迁移

我有两个模型: user.js的 'use strict' module.exports = function(sequelize, DataTypes) { var User = sequelize.define('User', { gid: { type: DataTypes.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true }, email: { type: DataTypes.STRING, allowNull: false }, password: { type: DataTypes.STRING, allowNull: false }, newsletters: { type: 'NUMERIC', allowNull: false, defaultValue: '1' }, status: { type: 'NUMERIC', allowNull: false, defaultValue: […]

如何添加,删除Sequelize CLI中的新列

我刚开始使用Sequelize和Sequelize CLI 由于这是一个开发时间,因此频繁地添加和删除列。 什么是最好的方法添加一个新的列到现有的模型? 例如,我想要一个新的专栏“ 完成 ”到Todo模型。 我将这个列添加到models / todo.js。 下一步是什么? 我试过sequelize db:migrate 不工作: “没有执行迁移,数据库模式已经是最新的。”

在续集种子中findlogging

我一直在试图为我的项目写一些种子,但是我遇到了一些麻烦。 我与我的users和roles表有着many-to-many关系。 所以,当我播种数据库时,我需要添加一个正确的ID到我的连接表的logging。 为了做到这一点,我需要find用户通过email和angular色的name并得到ids ,这就是问题所在。 我无法在续集网站上find任何好的文档。 我正在使用sequelize-cli来播种和迁移东西。 我作为一个参数queryInterface ,但我找不到任何示例或提到什么事情可以实际上做。 只是一些简单的例子,让我通过迁移(以某种方式),我能在谷歌find。 我已经通过使用“脏伎俩”来解决这个问题了。 // user_seeds.js up: function (queryInterface, Sequelize) { return queryInterface.bulkInsert(table, [{ id: 1, name: 'John doe', email: 'john@doe.com', created_at, updated_at }], {}); // roles_seeds.js up: function (queryInterface, Sequelize) { return queryInterface.bulkInsert(table, [{ id: 1, name: 'admin', created_at, updated_at }, { id: 2, name: 'user', created_at, […]

npm运行sequelize无法parsing

我正在尝试使用序列化迁移: npm install –save sequelize-cli 然后我把它添加到package.json中: "scripts": { "sequelize": "sequelize" }, 然后我尝试: npm run sequelize help:init 我得到这个错误: Unable to resolve sequelize package in C:\Projectx 该图书馆可以在该项目中find: node_modules/.bin/sequelize 更新 : 通过安装sequelize解决了它: npm install –save sequelize

Sequelize:根据请求在运行时连接到数据库

我正在做一个node.js应用程序,我需要连接到多个数据库。 其中一个数据库是中央数据库,其中包含所有人共同的信息。 然后有根据国家储存数据的国家级数据库。 我在应用程序中使用续集ORM。 数据库是postgresql。 框架是明确的。 问题是我想根据请求使用哪个数据库来决定运行时间,模型应该自动连接到适当的数据库。 我已经看到这个问题,但没有发现它有帮助。 我也检查了另一个论坛,但没有发现任何东西。