GRS
GRS

Reputation: 1967

Typeorm - Disable default creation of columns id, createdAt, updatedAt when entity is synced

I am using typeorm with nest.js and I have a session entity like the below

import { Column, Entity, PrimaryColumn } from 'typeorm';
@Entity('session')
export class Session {
  @PrimaryColumn('varchar', { length: 255 })
  sid: string;

  @Column('jsonb')
  sess: JSON;

  @Column('timestamptz', { nullable: true })
  expire: string;
}

Whenever I start the server I have enabled synchronize: true in the configuration.

This is creating a table like the below, with id, createdAt, updatedAt being created by default even though not mentioned in the entity schema.

enter image description here

How to disable this default creation of (id, createdAt, updatedAt)columns and restrict the table to be created with only the columns I have mentioned in the entity?

Upvotes: 0

Views: 1171

Answers (1)

omidh
omidh

Reputation: 2822

It's probably created by previous attempts. Try these steps to fix the issue:

  1. Drop the database
  2. run npm run prebuild
  3. run npm run build
  4. run npm run start

Upvotes: 1

Related Questions