Skip to content
Advertisement

TypeORM fails to connect without any error message

I am trying to get started with TypeORM, but cannot get createConnection to work. I run the default tpyeorm init server file, but there is not error or logging shown, nor is the postgres DB updated.

index.ts

JavaScript

ormconfig.json (note: I changed the postgres password to ‘root’)

JavaScript

running start gives the following output:

JavaScript

Note that none of the other logging statements are hit. Why is that? Neither are errors shown.

postgres databases on my local machine:

JavaScript

The default User table is not created after trying to start the server

JavaScript

Update

I followed and downloaded the code from this tutorial, and magically it worked. But unfortunately my old project still failed…

Eventually I tried messing with my models, and discovered that the failure was due to TypeORM not liking how I setup some of my models. I have a model, A that can have two arrays of model B (Bs that exist before event A, and Bs that exist after event A).

In TypeORM I had set this up to be 2 OneToMany relationships on A, and 2 ManyToOne relatonships on the B class. Something about this crashed TypeORM though. What is the correct way to do this instead?

A:

JavaScript

B:

JavaScript

Advertisement

Answer

In the update I say that it failed to start due to an Entity setup issue. Entity A can have many Bs, both before and after an event. I ended up getting it working by setting up the Entities as so:

JavaScript

I also had to update my TypeORM package…

Edit: Duplicating your entities causes double the work when creating resolvers, seeders, and when querying on the front end. An easier way is to add a ‘Type’ enum field/column on the entity.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement