'How I can use exist table in mysql using typeorm entity?

Using typeorm, I connect to the mysql db. Several tables already exist in the database. I try to describe a table using the entity module, but my definition overwrites an existing table. How with entity I can fully inherit from an existing table?

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;
}


Solution 1:[1]

You could set the the synchronize property to false with @Entity like below.

@Entity({name:"devices", synchronize: false})

Solution 2:[2]

In ormconfig.json

change

{
  "type": "mysql",
  "host": "localhost",
  "port": 3306,
  "database": "demo",
  "username": "root",
  "entities": ["src/**/**.entity{.ts,.js}"],
  "synchronize": true
}

to

{
  "type": "mysql",
  "host": "localhost",
  "port": 3306,
  "database": "demo",
  "username": "root",
  "entities": ["src/**/**.entity{.ts,.js}"],
  "synchronize": false
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 senuraa
Solution 2 jctaoo