Versions
I write a model like this.
MembersInWorkspace.ts
@Table({ freezeTableName: true, underscored: true, timestamps: false })
export default class MembersInWorkspace extends Model<MembersInWorkspace> {
@Column(DataType.BIGINT)
@PrimaryKey
@AutoIncrement
id!: number
@ForeignKey(() => User)
@Column
user_id!: number
@ForeignKey(() => Workspace)
@Column
workspace_id!: number
...
}
Workspace.ts
import { AllowNull, AutoIncrement, BelongsTo, BelongsToMany, Column, ForeignKey, HasMany, Model, PrimaryKey, Table } from 'sequelize-typescript'
import Files from './Files'
import Invitations from './Invitations'
import MembersInWorkspace from './MembersInWorkspace'
import Messages from './Messages'
import User from './User'
@Table({ freezeTableName: true, underscored: true, timestamps: false })
export default class Workspace extends Model<Workspace> {
@Column
@PrimaryKey
@AutoIncrement
id!: number
@ForeignKey(() => User)
@Column
@AllowNull(false)
creator_id!: number
@BelongsTo(() => User)
creator!: User
@BelongsToMany(() => User, () => MembersInWorkspace)
members!: User[]
@HasMany(() => Messages)
messages!: Messages[]
@HasMany(() => Files)
files!: Files[]
@HasMany(() => Invitations)
invitations!: Invitations
...
}
User.ts
@Table({ freezeTableName: true, underscored: true, timestamps: false })
export default class User extends Model<User> {
@Column
@PrimaryKey
@AutoIncrement
@AllowNull(false)
id!: number
@HasMany(() => Workspace)
createWorkspaces!: Workspace[]
@BelongsToMany(() => Workspace, () => MembersInWorkspace)
joinWorkspaces!: Workspace[]
...
}
i got a error like
throw new Error(`@Column annotation is missing for "${propertyName}" of class "${target.constructor.name}"` +
^
Error: @Column annotation is missing for "id" of class "MembersInWorkspace" or annotation order is wrong.
at Object.addAttributeOptions (/Users/dany/workspace/paperly/strum-back/node_modules/sequelize-typescript/dist/model/column/attribute-service.js:48:15)
at AllowNull (/Users/dany/workspace/paperly/strum-back/node_modules/sequelize-typescript/dist/model/column/column-options/allow-null.js:7:62)
at DecorateProperty (/Users/dany/workspace/paperly/strum-back/node_modules/reflect-metadata/Reflect.js:553:33)
what is the problem for my code?
FYI I'm having trouble finding this in the documentation but it appears that the order of the annotations matters. I would move @Column to the bottom of your list of decorators so that it comes just prior to the variable declaration. I know this issue is closed and this isn't the proper place for questions like this but just throwing this out there as this is the first result you get in google searching for this error.
@chriswininger It's really helful ! Thanks!
Most helpful comment
FYI I'm having trouble finding this in the documentation but it appears that the order of the annotations matters. I would move @Column to the bottom of your list of decorators so that it comes just prior to the variable declaration. I know this issue is closed and this isn't the proper place for questions like this but just throwing this out there as this is the first result you get in google searching for this error.