简体   繁体   中英

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```

TypeORM offers so many possibilities that it is easy to get lost in them. ;-)

You can modify the local database and generate migration files:

typeorm migration:generate -n UserMigration

You can modify entities and synchronize changes: (you need this)

typeorm schema:sync

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM