typeorm中表没有主键时会报错说表必须有主键字段的问题
Created by: yinlianghui
现象:数据库中表未设置主键字段,yml对象配置文本中不标记任何字段为主键,则会报错MissingPrimaryColumnError: Entity "TestFieldTypesForSqlserver" does not have a primary column. Primary column is required to have in all your entities. Use @PrimaryColumn decorator to add a primary column to your entity.
虽然可以在yml对象配置文件中标记某个字段为主键(不需要把数据库表也加主键)来避开这个报错,但是不合理,也可能存在某些隐患。
typeorm支持对象类型:
export type TableType = "regular"|"view"|"junction"|"closure"|"closure-junction"|"entity-child";
需要判断没有主键时设置TableType为junction(连接表),以解决此问题