Search code examples
node.jstypescriptpostgresqlnestjstypeorm

Column X of relation Y contains null values


When inserting first admin into my database I get this error message and don't know how to solve it:

[Nest] 13803   - 04/27/2021, 23:03:02   [TypeOrmModule] Unable to connect to the database. Retrying (6)... +3176ms
QueryFailedError: column "name" of relation "admin" contains null values

Other tables work just fine so far and without errors.

Column name in admin table is not null it contains value: admin table

Register service:

async register(registerInput: RegisterInput): Promise<void> {
    const { key, name, password, email } = registerInput;

    const hashedKey = createHash('sha256')
      .update(key)
      .digest('hex');

    const invite = await this.invitesRepository.findOne({ key: hashedKey });

    if (!invite) {
      throw new UnauthorizedException();
    }

    const newAdmin = await this.adminsRepository.create({
      name,
      password,
      email,
    });
    await this.adminsRepository.save(newAdmin);

    await this.invitesRepository.delete({ id: invite.id });
  }

Solution

  • I deleted dist directory and rebuilt the code. This solved the issue.