Typescript TypeForm:无法读取未定义的属性“id”
我试着在typeform中使用mirgation,如下所示: TableExample.entity.ts @实体{name:'table_example'} 导出类TableExampleEntity{ 构造函数属性:TableExampleInterface{ this.id=properties.id; } @主柱{ 名称:“id”, 类型:“uuid”, 已生成:“uuid”, 默认值:“uuid\u generate\u v4”, } id?:字符串; } TableExample.interface.ts 导出接口表ExampleInterface{ id?:字符串; } 和迁移文件 从“typeorm”导入{MigrationInterface,QueryRunner,Table}; 导出类createSongEntities1591077091789实现迁移接口{ 公共异步upqueryRunner:QueryRunner:Promise{ 等待queryRunner.createTablenew表{ 名称:'table_example', 栏目:[ { 名称:“id”, 类型:“uuid”, 生成策略:“uuid”, 默认值:“uuid\u generate\u v4”, 是的, }, ], }; } 公共异步downqueryRunner:QueryRunner:Promise{ 等待queryRunner.dropTable'table_example'; } } 运行mirgation时,节点服务器引发了此错误 堆栈跟踪Typescript TypeForm:无法读取未定义的属性“id”,typescript,migration,typeorm,Typescript,Migration,Typeorm,我试着在typeform中使用mirgation,如下所示: TableExample.entity.ts @实体{name:'table_example'} 导出类TableExampleEntity{ 构造函数属性:TableExampleInterface{ this.id=properties.id; } @主柱{ 名称:“id”, 类型:“uuid”, 已生成:“uuid”, 默认值:“uuid\u generate\u v4”, } id?:字符串; } TableExample.i
Error during migration run:
TypeError: Cannot read property 'id' of undefined
at new TableExampleEntity (...\src\entities\TableExample.entity.ts:17:34)
at EntityMetadata.create (...\src\metadata\EntityMetadata.ts:524:19)
at EntityMetadataValidator.validate (...\src\metadata-builder\EntityMetadataValidator.ts:112:47)
at ...\src\metadata-builder\EntityMetadataValidator.ts:45:56
at Array.forEach (<anonymous>)
at EntityMetadataValidator.validateMany (...\src\metadata-builder\EntityMetadataValidator.ts:45:25)
...
这里怎么了?请帮帮我 来自TypeForm文档: 使用实体构造函数时,其参数必须是可选的。由于ORM在从数据库加载时创建实体类的实例,因此它不知道您的构造函数参数
在您的例子中,typeorm正在创建实体的实例,并且没有在构造函数中传递任何内容。因此属性参数未定义。来自TypeForm文档: 使用实体构造函数时,其参数必须是可选的。由于ORM在从数据库加载时创建实体类的实例,因此它不知道您的构造函数参数
在您的例子中,typeorm正在创建实体的实例,并且没有在构造函数中传递任何内容。所以属性参数未定义。完整堆栈跟踪?Hi bro@AluanHaddad,我在这里添加了堆栈,请帮助我在这里查找问题,感谢完整堆栈跟踪?Hi bro@AluanHaddad,我在这里添加了堆栈,请帮我查找问题,非常感谢