Error Handling/에러핸들링

throw new Error(`Unrecognized datatype for attribute "${this.name}.${name}"`); Unrecognized datatype for attribute

sangwoo_rhie 2023. 7. 6. 11:55

 

 

VSCode에서 모델 안에 있는 특정 테이블의 컬럼명을 변경하고 (Postlike.js의 id를 likedCount 로 변경, 그리고 CommentLikes 테이블 추가) MySQL 데이터베이스의 해당 테이블을 삭제한 뒤 다시 설치했다.

npx sequelize model:generate --name CommentLikes --attributes UserId:integer,PostId:integer,commentId:integer

 

그러고나니 commentlikes의 마이그레이션과 모델이 생성되었고, node app.js를 실행하려고 하니 다음과 같은 오류가 발생했다.

 

$ node app
C:\Users\admin\Desktop\코딩\NODE\4th Week\Sequelize-Relations (Lv.4)\node_modules\sequelize\lib\model.js:726
        throw new Error(`Unrecognized datatype for attribute "${this.name}.${name}"`);
        ^

Error: Unrecognized datatype for attribute "CommentLikes.PostId"
    at C:\Users\admin\Desktop\코딩\NODE\4th Week\Sequelize-Relations (Lv.4)\node_modules\sequelize\lib\model.js:726:15
    at C:\Users\admin\Desktop\코딩\NODE\4th Week\Sequelize-Relations (Lv.4)\node_modules\lodash\lodash.js:13469:38
    at C:\Users\admin\Desktop\코딩\NODE\4th Week\Sequelize-Relations (Lv.4)\node_modules\lodash\lodash.js:4967:15
    at baseForOwn (C:\Users\admin\Desktop\코딩\NODE\4th Week\Sequelize-Relations (Lv.4)\node_modules\lodash\lodash.js:3032:24)
    at Function.mapValues (C:\Users\admin\Desktop\코딩\NODE\4th Week\Sequelize-Relations (Lv.4)\node_modules\lodash\lodash.js:13468:7)
    at CommentLikes.init (C:\Users\admin\Desktop\코딩\NODE\4th Week\Sequelize-Relations (Lv.4)\node_modules\sequelize\lib\model.js:723:28)
    at module.exports (C:\Users\admin\Desktop\코딩\NODE\4th Week\Sequelize-Relations (Lv.4)\models\commentlikes.js:17:16)
    at C:\Users\admin\Desktop\코딩\NODE\4th Week\Sequelize-Relations (Lv.4)\models\index.js:30:54
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (C:\Users\admin\Desktop\코딩\NODE\4th Week\Sequelize-Relations (Lv.4)\models\index.js:29:4)

Node.js v18.16.0

 

문제는 오타였다. 일단 에러메시지를 잘 봐야한다.

Unrecognized datatype for attribute "CommentLikes.PostId" 라고 되어있으면 CommentLikes모델의 PostId가 인식할 수 없다는 뜻이다.

아래에 26번째 줄을 postId가 아닌 type으로 바꿔야 한다.

 

그리고 다른 블로그를 보니 모델 및 마이그레이션의 데이터타입을 모두 대문자로 바꿔야 한다고 한다.

위에 보면 INTEGER, NOW, DATE, STRING 이런게 데이터타입이고 다 대문자로 써야 한다.