sequelize-cli

Updating instance with multiple associations in Sequelize

点点圈 提交于 2020-07-23 06:13:18
问题 I am able to create records in my MySQL DB with sequelize and NodeJS. But now I am trying to update records in my Database. I have NodeJS as backend and my DB is MySql. Sequelize is my ORM. In Sequelize 5, I have a couple of classes: WorkOder, User (mechanic), Customer, Client and ExpertiseOffice. My datamodel is not complex, there are only 1:1 relations. A WorkOrder has one customer, one Client and one ExpertiseOffice. I use Postman to test my api's. With creating a WorkOrder with some

sequelize.sync({ force: true }) is not working some times

╄→гoц情女王★ 提交于 2020-05-15 05:19:24
问题 i am using gulp tasks for migration of database. For testing purpose i am using different database. so i need exactly same database. i am trying to do with sequelize.sync({ force: true }) but its not working. i am having my all models in portal-model. here is the code: const models = require('portal-models'); gulp.task('migrate', ['create-database'], (done) => { models.sequelize.query('SET FOREIGN_KEY_CHECKS = 0') .then(() => models.sequelize.sync({ force: true, alter: true })) .... .... ....

sequelize.sync({ force: true }) is not working some times

久未见 提交于 2020-05-15 05:19:06
问题 i am using gulp tasks for migration of database. For testing purpose i am using different database. so i need exactly same database. i am trying to do with sequelize.sync({ force: true }) but its not working. i am having my all models in portal-model. here is the code: const models = require('portal-models'); gulp.task('migrate', ['create-database'], (done) => { models.sequelize.query('SET FOREIGN_KEY_CHECKS = 0') .then(() => models.sequelize.sync({ force: true, alter: true })) .... .... ....

Sequelize not creating model association columns

我的梦境 提交于 2020-03-03 09:09:04
问题 I'm a little confused with when Sequelize creates the fields for associations. I've created my migrations using sequelize-cli. This generated a migration and model file. Then in the model file I populated my associations. Then ran npx sequelize-cli db:migrate . This creates the tables but not the foreign keys needed for the associations defined in the model. For example: migration-quesions: "use strict"; module.exports = { up: (queryInterface, Sequelize) => { return queryInterface.createTable

How to SELF JOIN using Sequelize in Node

拈花ヽ惹草 提交于 2020-01-15 11:42:30
问题 I'm using sequelize-cli for migrations and have researched different scenarios but there doesn't seem to be a definite solid answer as to how to self join. I want to have a join table called friendships which joins users and friends (which are essentially just users). More specifically trying to gain an understanding about the difference between "through" and "as" in this situation. 1) This is my friendship table. Getting tripped up on the second association. I have created two columns, one

How to SELF JOIN using Sequelize in Node

只愿长相守 提交于 2020-01-15 11:41:48
问题 I'm using sequelize-cli for migrations and have researched different scenarios but there doesn't seem to be a definite solid answer as to how to self join. I want to have a join table called friendships which joins users and friends (which are essentially just users). More specifically trying to gain an understanding about the difference between "through" and "as" in this situation. 1) This is my friendship table. Getting tripped up on the second association. I have created two columns, one

Sequelize belongsToMany additional attributes in join table

旧时模样 提交于 2020-01-14 03:23:24
问题 I'm having problem with an additional attribute in the join table of the belongsToMany relation. In the set or add method this attribute is not being passed to mysql. I'm following the documentation pass as "through" the attribute within the set method, but it is not working. Would anyone know what could be wrong since following the documentation is not working? Note: The registration and update of the join is correct, only the additional attribute that is not being passed to the table.

How to set primary key type to UUID via Sequelize CLI

依然范特西╮ 提交于 2020-01-11 19:53:28
问题 I'm creating a DB model via Sequelize CLI with this command: sequelize model:create --name User --attributes "firstname:string, lastname:string" This creates the corresponding migration script: 'use strict'; module.exports = { up: function(queryInterface, Sequelize) { return queryInterface.createTable('Users', { id: { allowNull: false, autoIncrement: true, primaryKey: true, type: Sequelize.INTEGER }, firstname: { type: Sequelize.STRING }, lastname: { type: Sequelize.STRING }, createdAt: {

Running Sequelize Migration and Node Server in Same Command Won't Start Server Up

蹲街弑〆低调 提交于 2020-01-03 05:10:08
问题 If I try to run my sequelize migrations and then run my Node server in the same command, I run into the issue of my server never starting up. If the migrations have already been run before, the sequelize db:migrate command doesn't go past the "No migrations were executed, database schema was already up to date." message, and my second command is never able to run. If the migration has not run before, everything runs properly in sequence. This is my npm start command: sequelize db:migrate &&

Sequelize belongsToMany validation error

走远了吗. 提交于 2019-12-24 07:38:18
问题 I'm facing a problem since 3 days. I would like to create a multiple relation n:m in Sequelize but I'm getting an error message : " Unhandled rejection SequelizeUniqueConstraintError: Validation error ". So I have 3 tables : Serie. Episode. Season (in this table I would like to add relation to Serie and Episode ). Here is the definition of Serie : var Serie = sequelize.define('Serie', { idSerie: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true }, name: DataTypes.STRING }, {