sequelize-cli

sequelize select and include another table alias

故事扮演 提交于 2019-12-24 04:02:13
问题 I'm using sequelize to acess a postgres database and I want to query for a city and for example include the "Building" table but I want to rename the output to "buildings" and return the http response but I have this error: { SequelizeEagerLoadingError: building is associated to city using an alias. You'v e included an alias (buildings), but it does not match the alias defined in your a ssociation. City.findById(req.params.id,{ include: [ { model: Building, as: "buildings" } ] }).then(city =>

Should Sequelize migrations update model files?

六眼飞鱼酱① 提交于 2019-12-20 20:02:35
问题 Are Sequelize migrations supposed to keep your model files in line with your database? I used the sequelize cli to bootstrap a simple project and create a model node_modules/.bin/sequelize model:generate --name User --attributes email:string . I migrated this with no issue. Then I created the following migration file to add a notNull constraint to the user email attribute. updateEmail migration const models = require("../models") module.exports = { up: (queryInterface, Sequelize) => { return

How to connect database with different credential dynamically for different server in production level?

非 Y 不嫁゛ 提交于 2019-12-11 14:59:41
问题 I want to connect the databases which are for the different servers (like dev, staging, live, production). There are different databases and credential for all the server. When a server will be called it will access data only that particular database. In my code, I am using node js with sequelize for the database connection to build the API in GraphQL.How can I do this? I have already tried a lot. Please suggest to me. If need code I can post it here. 回答1: The best way to do this is to keep a

Sequelize Migration: relation <table> does not exist

坚强是说给别人听的谎言 提交于 2019-12-11 08:55:57
问题 I'm working through an Author hasMany Books example and am attempting to run a sequelize-cli migration, but am getting the following issue when I run the following migration: ERROR: relation "authors" does not exist This is the first migration to create an author: 'use strict'; module.exports = { up: (queryInterface, Sequelize) => { return queryInterface.createTable('Authors', { id: { allowNull: false, autoIncrement: true, primaryKey: true, type: Sequelize.INTEGER }, firstName: { type:

Include unexpected. Element has to be either a Model, an Association or an object

半城伤御伤魂 提交于 2019-12-11 05:54:07
问题 I have a problem trying to configure postrgres with nodeJs, i followed this tutorial and i get a error that doesn't specify anything about what is wrong: here is the stacktrace Unhandled rejection Error: Include unexpected. Element has to be either a Model, an Association or an object. at C:\Users\FilipeCosta\desktop\FloraApp\server\node_modules\sequelize\lib\model.js:1976:15 at Array.map (native) at conformOptions (C:\Users\FilipeCosta\desktop\FloraApp\server\node_modules\sequelize\lib\model

How to add column in Sequelize existing model?

喜夏-厌秋 提交于 2019-12-09 12:01:17
问题 I have added a model and a migration file using this command node_modules/.bin/sequelize model:generate --name User --attributes firstName:string,lastName:string,email:string Now I wanted to add few more fields like gender and age in to the existing table(model). I changed model manually and fire this command node_modules/.bin/sequelize db:migrate But it is responding that "No migrations were executed, database schema was already up to date. " User.js 'use strict'; module.exports = (sequelize

Sequelize.js still deletes table row even if paranoid is set to true

天涯浪子 提交于 2019-12-07 20:17:28
问题 I'm having trouble getting Sequelize.js to soft delete the rows in my table. I used Sequelize cli to do all my migrations and I'm not using the sync feature to resync the database on start. I have the timestamp fields and even the deletedAt field in my migration and models (model has paranoid: true also) and no matter what it still deletes the row instead of adding a timestamp to the deletedAt field. I noticed when do any querying it doesn't add the deletedAt = NULL in the query like I've

Sequelize belongsToMany additional attributes in join table

最后都变了- 提交于 2019-12-06 15:05:22
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. Functionality Model: export default function(sequelize, DataTypes) { const Functionality = sequelize.define(

Is it possible to fetch data from multiple tables using GraphQLList

…衆ロ難τιáo~ 提交于 2019-12-04 06:22:05
问题 In GraphQL we can write the object type in GraphQLList and fetch all the fields. I am using Association and it is joining the two tables but I am unable to fetch the field of both the tables. It only takes the fields what I have written in GraphQLList.As I want the list of data. Here is the code films table: module.exports =(sequelize, DataTypes) => { const films = sequelize.define( 'films', { id:{ type: DataTypes.INTEGER, primaryKey: true, allowNull: false, }, name: { type: DataTypes.STRING,

How to add column in Sequelize existing model?

▼魔方 西西 提交于 2019-12-03 14:09:50
I have added a model and a migration file using this command node_modules/.bin/sequelize model:generate --name User --attributes firstName:string,lastName:string,email:string Now I wanted to add few more fields like gender and age in to the existing table(model). I changed model manually and fire this command node_modules/.bin/sequelize db:migrate But it is responding that "No migrations were executed, database schema was already up to date. " User.js 'use strict'; module.exports = (sequelize, DataTypes) => { var User = sequelize.define('User', { firstName: DataTypes.STRING, lastName: