【发布时间】:2020-03-21 18:15:42
【问题描述】:
使用 typeorm,我连接到 mysql 数据库。数据库中已经存在几个表。我尝试使用实体模块来描述表,但我的定义覆盖了现有表。如何使用实体从现有表中完全继承?
import "reflect-metadata";
import { Entity, PrimaryGeneratedColumn, Column, PrimaryColumn, OneToMany } from "typeorm";
@Entity("devices")
export class Devices {
@PrimaryGeneratedColumn()
ID: number;
@Column({ type: "varchar", length: 255 })
Name: string;
@Column({ type: "int", nullable: false })
DevID: number;
@Column({ type: "int", nullable: false })
Longtitude: number;
@Column({ type: "int", nullable: false })
Latitude: number;
@PrimaryColumn({ type: "varchar", length: 255 })
URL_VWS: string;
}
【问题讨论】:
-
你的表是如何在 Mysql 中定义的,你应该提供它的模式,因为没有它就不可能回答你的问题
-
您还应该提供带有迁移和同步信息的
ormconfig.json文件。如果您使用sync选项,您将无法安全地处理它。
标签: javascript mysql node.js express typeorm