Search code examples
node.jspostgresqltypeormtypeorm-activerecord

TypeOrm migrations not generating


I am fairly new to TypeOrm and I am trying to use it for a project but I am facing issue in generating migrations. I have a Postgres App running on my local at port 5432.

My Entity looks like this:

@Entity()
export class User {

  @PrimaryGeneratedColumn()
  id!: number;

  @Index({ unique: true })
  @Column('text', {nullable:true})
  username!: string;

  @Index({ unique: true })
  @Column('text', {nullable:true})
  @IsEmail()
  email!: string;

  @Index()
  @Column('bool',{nullable:true, default: false})
  emailVerified!: boolean;


  @UpdateDateColumn()
  @IsDate()
  updateDate!: Timestamp;

  @Column('text',)
  about!: string;
};    

and my OrmConfig looks like this

{
  "entities": ["src/entity/*.js"],
  "migrations": ["src/migration/*.js"],
  "subscribers": ["src/subscriber/**/*.js"],
  "cli": {
    "migrationsDir": "src/migration",
    "entitiesDir": "src/entities",
    "subscribersDir": "src/subscriber"
  },  
  "url": "postgres://@0.0.0.0:5432/nftme_dev",
  "type": "postgres",
  "synchronize": true
}

When I run:

yarn run typeorm migration:generate -n initial

It throws an error saying:

$ node_modules/.bin/typeorm migration:generate -n initial
No changes in database schema were found - cannot generate a migration. To create a new empty migration use "typeorm migration:create" command```

Solution

  • So I finally was able to nail this down after debugging it for a day.

    So when I was using synchronize: true option the schema was already created for my entities in the database and when I tried to generate it failed as there was nothing that changed.

    I created a fresh db and tried to generate migrations and it worked.