TypeORM does not create tables, columns etc

Even though the previous answers are acceptable for development environment, they are wrong for production.

What you are looking for are migrations. Migrations are executed when connection is established and are recorded - no migration will run more than once. TypeORM also provides CLI which allows you to generate migrations (read more here), making it much faster to create them. TypeORM also marks each migration with a timestamp prefix, ensuring they will run in proper sequence - sometimes you might want to run migrations in primary tables first, sometimes on supporting tables. When configuring connection, you load migrations like this:

createConnection({
    type: 'mysql',
    host: 'typeorm2.cn32tstd6wqk.eu-central-1.rds.amazonaws.com',
    port: 1234,
    username: 'username',
    password: 'password',
    database: 'dbname',
    entities: [
        // __dirname + '/../**/*.entity{.ts,.js}'
        UserPassword,
        User
    ],
    migrations: ['./migrations/*.js'],
    synchronize: false
})

Migrations are built composed of 2 parts - up (migration code) and down (code to revert migration). Simple example:

import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddImageToUser implements MigrationInterface {

    async up(queryRunner: QueryRunner): Promise<any> {
        await queryRunner.query(
                'ALTER TABLE "user" ADD image varchar(255)'
        );
    }
    async down(queryRunner: QueryRunner): Promise<any> {
        await queryRunner.query(
                'ALTER TABLE "user" DROP COLUMN image'
        );
    }
}

If you want to read more, TypeORM has detailed description on their official Git repository here

In general, it is not good to leave the synchronization of the data and schema to the framework. It is something that should be done by you to ensure the database schema will be preserved. The CLI I linked before also allows you to run migrations and therefore test them before pushing changes to production.


Connection has ‘synchronize()’ method. You can use it to create tables and columns automatically:

const connection = await createConnection(...);
await connection.synchronize();