Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when trying to make a connection. #115

Open
abcdefghijklmnop opened this issue Feb 15, 2021 · 1 comment
Open

Error when trying to make a connection. #115

abcdefghijklmnop opened this issue Feb 15, 2021 · 1 comment
Assignees

Comments

@abcdefghijklmnop
Copy link

The problem is:
Could not save entity.
I'm using TypeORM with Postgres.

SEED file:

create-article.seed.ts:

...

export class CreateOpenTournament implements Seeder {
  public async run(factory: Factory): Promise<void> {
    await factory(Article)().create();
  }
}

FACTORY file:

article.factory.ts:

...

define(Article, (faker: typeof Faker) => {
  const article = new Article();

  article.id = faker.random.uuid();
  article.publicedDate = new Date('2012-10-07 12:00');
  article.numberOfViews = 20;
  article.type = ArticleType.BLOG;
  article.status = factory(Status)() as any;
  article.content = factory(ArticleContent)() as any;
  article.contributors = [factory(ArticleMapping)() as any];
  article.category = factory(Category)() as any;
  article.tags = [factory(TagMapping)() as any]; // <-- Error here
  article.ratings = null;

  return article;
});

tagMapping.factory.ts:

...
define(TagMapping, (faker: typeof Faker) => {
  const tagMapping = new TagMapping();
  tagMapping.id = faker.random.uuid();
  tagMapping.isMain = false; //boolean;	<-- here is false but in compile null
  tagMapping.tag = factory(Tag)() as any;

  return tagMapping;
});

Entity file:

article.entity.ts:

...
@Entity()
export class Article extends DefaultEntity {
  ...

  @ApiProperty({ type: [TagMapping], description: 'The Tags belong to this article.' })
  @ManyToMany(() => TagMapping, { cascade: true, eager: true })
  @JoinTable()
  tags: TagMapping[];

  ...
}

This is what I get when running the seeder:

...
❌  Could not save entity
QueryFailedError: null value in column "isMain" violates not-null constraint
  ...
  code: '23502',
  detail: 'Failing row contains (93f39f1d-64b6-41b7-b127-ce9e6f1dcebc, 2021-02-15 11:29:35.901828+01, 2021-02-15 11:29:35.901828+01, null, null, null).',
	...
  query: 'INSERT INTO "tag_mapping"("id", "createDate", "updateDate", "deleteDate", "isMain", "tagId") VALUES (DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT) RETURNING "id", "createDate", "updateDate", "deleteDate"',
  parameters: []
}
× Could not run the seed CreateOpenTournament!
Error: Could not save entity
	...
npm ERR! code 1
...

Sorry for my bad English.

@jorgebodega
Copy link
Collaborator

Hi! Sorry for late response.

I have to check this deeply, not sure how is the behaviour when working on arrays on factories.

@jorgebodega jorgebodega self-assigned this Oct 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants