title: TypeORM: QueryFailedError: relation does not exist
body: <p>I need a little help with migration. I'm trying to seed DB using migration. But I get an error &quot;QueryFailedError: relation &quot;account&quot; does not exist&quot;. I think it's just typical newbie mistake. So please check my code:</p>
  <p><strong>account.entity.ts</strong></p>
  <pre class="lang-ts prettyprint-override"><code>import { BeforeInsert, Column, Entity, OneToMany } from 'typeorm';
  import { AbstractEntity } from '../../common/abstract.entity';
  import { SourceEntity } from '../source/source.entity';
  import { UtilsService } from '../../shared/services/utils.service';
  
  @Entity({ name: 'account' })
  export class AccountEntity extends AbstractEntity {
    @Column({ unique: true })
    username: string;
  
    @Column({ nullable: true })
    password: string;
  
    @OneToMany(() =&gt; SourceEntity, (source) =&gt; source.account, {
      cascade: true,
    })
    sources: SourceEntity[];
  
    @BeforeInsert()
    async setPassword() {
      this.password = UtilsService.generateHash(this.password);
    }
  }
  </code></pre>
  <p><strong>seed-data.migration.ts</strong></p>
  <pre class="lang-ts prettyprint-override"><code>import { getCustomRepository, MigrationInterface, QueryRunner } from 'typeorm';
  import { AccountRepository } from '../modules/account/account.repository';
  import { SourceRepository } from '../modules/source/source.repository';
  
  type DataType = {
    username: string;
    password: string;
    sources: { username: string }[];
  };
  
  export class SeedData1617243952346 implements MigrationInterface {
    private data: DataType[] = [
      {
        username: 'test',
        password: 'password',
        sources: [
          { username: 'some_test' },
          { username: 'okey_test' },
          { username: 'super_test' },
        ],
      },
      {
        username: 'account',
        password: 'password',
        sources: [
          { username: 'some_account' },
          { username: 'okey_account' },
          { username: 'super_account' },
        ],
      },
    ];
  
    public async up(): Promise&lt;void&gt; {
      await Promise.all(
        this.data.map(async (item) =&gt; {
          const accountRepository = getCustomRepository(AccountRepository);
          const accountEntity = accountRepository.create();
          accountEntity.username = item.username;
          accountEntity.password = item.password;
  
          const sourceRepository = getCustomRepository(SourceRepository);
          const sources = [];
  
          await Promise.all(
            item.sources.map(async (sourceItem) =&gt; {
              const sourceEntity = sourceRepository.create();
              sourceEntity.username = sourceItem.username;
  
              sources.push(sourceEntity);
            }),
          );
  
          accountEntity.sources = sources;
          const account = await accountRepository.save(accountEntity);
          console.log('Account created:', account.id);
        }),
      );
    }
  
    public async down(): Promise&lt;void&gt; {
      await Promise.all(
        this.data.map(async (item) =&gt; {
          const sourceRepository = getCustomRepository(SourceRepository);
          const accountRepository = getCustomRepository(AccountRepository);
  
          const account = await accountRepository.findOne({
            where: { username: item.username },
          });
          if (account) {
            await Promise.all(
              item.sources.map(async (src) =&gt; {
                const source = await sourceRepository.findOne({
                  where: { username: src.username },
                });
                if (source) {
                  await sourceRepository.delete(source);
                }
              }),
            );
  
            await accountRepository.delete(account);
          }
        }),
      );
    }
  }
  </code></pre>
  <p><strong>source.entity.ts</strong></p>
  <pre class="lang-ts prettyprint-override"><code>import { Column, Entity, ManyToOne } from 'typeorm';
  import { AbstractEntity } from '../../common/abstract.entity';
  import { AccountEntity } from '../account/account.entity';
  
  @Entity({ name: 'source' })
  export class SourceEntity extends AbstractEntity {
    @Column({ unique: true })
    username: string;
  
    @Column({ default: true })
    overrideCaption: boolean;
  
    @ManyToOne(() =&gt; AccountEntity, (account) =&gt; account.sources)
    account: AccountEntity;
  }
  </code></pre>
  <p><strong>Error:</strong></p>
  <pre class="lang-sh prettyprint-override"><code>Error during migration run:
  QueryFailedError: relation &quot;account&quot; does not exist
      at new QueryFailedError (/home/wiha/dev/own/instahub/src/error/QueryFailedError.ts:9:9)
      at PostgresQueryRunner.&lt;anonymous&gt; (/home/wiha/dev/own/instahub/src/driver/postgres/PostgresQueryRunner.ts:228:19)
      at step (/home/wiha/dev/own/instahub/node_modules/tslib/tslib.js:143:27)
      at Object.throw (/home/wiha/dev/own/instahub/node_modules/tslib/tslib.js:124:57)
      at rejected (/home/wiha/dev/own/instahub/node_modules/tslib/tslib.js:115:69)
      at processTicksAndRejections (internal/process/task_queues.js:97:5) {
    length: 106,
    severity: 'ERROR',
    code: '42P01',
    detail: undefined,
    hint: undefined,
    position: '13',
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'parse_relation.c',
    line: '1191',
    routine: 'parserOpenTable',
    query: 'INSERT INTO &quot;account&quot;(&quot;id&quot;, &quot;created_at&quot;, &quot;updated_at&quot;, &quot;username&quot;, &quot;password&quot;) VALUES (DEFAULT, DEFAULT, DEFAULT, $1, $2) RETURNING &quot;id&quot;, &quot;created_at&quot;, &quot;updated_at&quot;',
    parameters: [
      'test',
      '$2b$10$iB6yb3D8e6iGmKoVAJ7eYeYfoItclw5lcVXqauPf9VH94DlDrbuSa'
    ]
  }
  </code></pre>
  <p>Tables are created in another migration</p>
  <p>DB: PostgreSQL 12.6<br />
  Node: 14.0.0<br />
  TypeORM: 0.2.32<br />
  @nestjs/typeorm: 7.1.5</p>