Migration does not create table in database. Typeorm, postgresql

Asked

Viewed 582 times

1

Good evening, you guys. In this project I am using typeorm to configure my database. I create my Migration, but when I execute the command Yarn typeorm Migration:run, It doesn’t create the table I set. It creates in the database only the Migrations table, the other table 'Employee' it does not create.

https://github.com/SamuelB7/employee_manager2

Can someone help me?


export class employees1603488907171 implements MigrationInterface {

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.createTable(new Table({
            name: 'employee',
            columns: [
                {
                    name: 'id',
                    type: 'integer',
                    unsigned: true,
                    isPrimary: true,
                    isGenerated: true,
                    generationStrategy: 'increment',
                },
                {
                    name:'name',
                    type: 'text',
                    isNullable: false
                }
            ]
        }))
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.dropTable('employee')
    }

}

  • Check that Migration is already in your Migrations table, run the down of that Migration and then run the up.

  • I decided to switch to sequelize, for what I researched, typeorm is more typescript oriented, and in this project that I am developing, I want to use only javascript.

1 answer

2

I saw that you have already changed typeORM for sequelize, but it follows a possible solution to this problem in case someone else comes to have.

Back in the archive ormconfig.json you need to specify the location of your Migrations and also for the typeORM cli, follow an example:

{
  "name": "default",
  "type": "postgres",
  "host": <<HOST>>,
  "port": <<PORT>>,
  "username": <<USERNAME>>,
  "password": <<PASSWORD>>,
  "database": <<DATABASE_NAME>>,
  "entities": [
    "./src/models/*.ts"
  ],
  "migrations": [
    "./src/database/migrations/*.ts"
  ],
  "cli": {
    "migrationsDir": "./src/database/migrations"
  }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.