-
카테고리
-
세부 분야
풀스택
-
해결 여부
미해결
index.js에서 hasmany 릴레이션 설정이 잘못된것 같아여
18.11.11 16:24 작성 조회수 369
0
안녕하세여 강사님~!
관계 설정을 하고 나서 npm start를 실행하니가 에러가 발생하는데여
어디서 잘못되었는지 파악을 잘못하겠어서 검토해주시면 감사할게여~!
에러 메세지와 index.js는 다음과 같습니다.
error message :
(base) C:fast_ajaxnpm_startlearn-sequelize>npm start
learn-sequelize@0.0.0 start C:fast_ajaxnpm_startlearn-sequelize
node ./bin/www
sequelize deprecated String based operators are now deprecated. Please use Symbol based operators for better security, read more at http://docs.sequelizejs.com/manual/tutorial/querying.html#operators node_modulessequelizelibsequelize.js:242:13
C:fast_ajaxnpm_startlearn-sequelizenode_modulessequelizelibassociationsmixin.js:13
throw new Error(this.name + '.hasMany called with something that\'s not a subclass of Sequelize.Model');
^
Error: user.hasMany called with something that's not a subclass of Sequelize.Model
at Function.hasMany (C:fast_ajaxnpm_startlearn-sequelizenode_modulessequelizelibassociationsmixin.js:13:13)
at Object. (C:fast_ajaxnpm_startlearn-sequelizemodelsindex.js:19:9)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object. (C:fast_ajaxnpm_startlearn-sequelizeapp.js:11:19)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object. (C:fast_ajaxnpm_startlearn-sequelizebinwww:7:11)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! learn-sequelize@0.0.0 start: node ./bin/www
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the learn-sequelize@0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:UsershyunsepkAppDataRoamingnpm-cache_logs2018-11-11T07_15_08_813Z-debug.log
===========================================================
index.js
============================================================
const path = require('path');
const Sequelize = require('sequelize');
const env = process.env.NODE_ENV || 'development'; // production
const config = require('../config/config.json')[env]
const sequelize = new Sequelize(config.database, config.username, config.password, config);
const db = {}
db.Sequelize = Sequelize;
db.sequelize = sequelize;
db.User = require('./user')(sequelize,Sequelize)
db.Comment = require('./comment')(sequelize,Sequelize)
// db.User.hasMany(db.Comment, {foreignkey: 'name'})
db.User.hasMany(db.Comment, { foreignKey: 'commenter', sourceKey:'id'});
db.Comment.belongTo(db.User, {foreignKey: 'commenter', targetKey:'id'});
module.exports = db;
====
답변을 작성해보세요.
0
답변 1