Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
    Sanjar B
    but I get an error
    SyntaxError: Invalid or unexpected token
    @Column({ nullable: true, default: null }) baseCurrency: string;
    Hi for the above column in my entity migration are getting generated each and every time for this field , Any suggestion please

    Hi there, using typeOrm on node application I have this error when i start transaction to mysql:

    (node:21) UnhandledPromiseRejectionWarning: QueryFailedError: ER_LOCK_WAIT_TIMEOUT: Lock wait timeout exceeded; try restarting transaction
        at new QueryFailedError (/opt/app/node_modules/typeorm/error/QueryFailedError.js:11:28)
        at Query.<anonymous> (/opt/app/node_modules/typeorm/driver/mysql/MysqlQueryRunner.js:170:45)
        at Query.<anonymous> (/opt/app/node_modules/mysql/lib/Connection.js:526:10)
        at Query._callback (/opt/app/node_modules/mysql/lib/Connection.js:488:16)
        at Query.Sequence.end (/opt/app/node_modules/mysql/lib/protocol/sequences/Sequence.js:83:24)
        at Query.ErrorPacket (/opt/app/node_modules/mysql/lib/protocol/sequences/Query.js:92:8)
        at Protocol._parsePacket (/opt/app/node_modules/mysql/lib/protocol/Protocol.js:291:23)
        at Parser._parsePacket (/opt/app/node_modules/mysql/lib/protocol/Parser.js:433:10)
        at Parser.write (/opt/app/node_modules/mysql/lib/protocol/Parser.js:43:10)
        at Protocol.write (/opt/app/node_modules/mysql/lib/protocol/Protocol.js:38:16)
        at Socket.<anonymous> (/opt/app/node_modules/mysql/lib/Connection.js:88:28)
        at Socket.<anonymous> (/opt/app/node_modules/mysql/lib/Connection.js:526:10)
        at Socket.emit (events.js:315:20)
        at addChunk (internal/streams/readable.js:309:12)
        at readableAddChunk (internal/streams/readable.js:284:9)
        at Socket.Readable.push (internal/streams/readable.js:223:10)
    (node:21) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 377404)
    21 - 2021-03-09T18:30:52.823Z - [ExceptionInterceptor] Database Exception - ER_LOCK_WAIT_TIMEOUT: Lock wait timeout exceeded; try restarting transaction  
    Error: Database Exception
        at PartiesService.deleteContractParties (/opt/app/dist/apps/contracts-api/main.js:10592:19)
        at runMicrotasks (<anonymous>)
        at processTicksAndRejections (internal/process/task_queues.js:93:5)
        at async ContractsService.update (/opt/app/dist/apps/contracts-api/main.js:11193:9)
    21 - 2021-03-09T18:30:52.824Z - [ExceptionInterceptor] Catched DatabaseException exception -> throw InternalServerErrorException 
    21 - 2021-03-09T18:30:52.826Z - [ExceptionHandler] DatabaseException: {"type":"DatabaseException","subType":"Party","internalMessage":"ER_LOCK_WAIT_TIMEOUT: Lock wait timeout exceeded; try restarting transaction"}  
    Error: Database Exception
        at CatchSubscriber.selector (/opt/app/dist/apps/contracts-api/main.js:1332:42)
        at CatchSubscriber.error (/opt/app/node_modules/rxjs/internal/operators/catchError.js:48:31)
        at MergeMapSubscriber.OuterSubscriber.notifyError (/opt/app/node_modules/rxjs/internal/OuterSubscriber.js:26:26)
        at InnerSubscriber._error (/opt/app/node_modules/rxjs/internal/InnerSubscriber.js:31:21)
        at InnerSubscriber.Subscriber.error (/opt/app/node_modules/rxjs/internal/Subscriber.js:72:18)
        at SwitchMapSubscriber.Subscriber._error (/opt/app/node_modules/rxjs/internal/Subscriber.js:92:26)
        at SwitchMapSubscriber.Subscriber.error (/opt/app/node_modules/rxjs/internal/Subscriber.js:72:18)
        at /opt/app/node_modules/rxjs/internal/util/subscribeToPromise.js:10:43
        at runMicrotasks (<anonymous>)
        at processTicksAndRejections (internal/process/task_queues.js:93:5)

    some one can help me to fix it? any hint or ideas are appreciated

    Not sure if this is on the right track but, from the error message it seems, that the DB transaction is taking a longer time that the configured timeout on the db lock - maybe try and simpler/faster query or adjust the timeout values
    Arun SD
    Hi guys anybody have any idea on how to mark a migration already ran in typeorm?
    Deepak Bansal
    what the datatype for tsvector col?
    Lawrence Bethlenfalvy
    How much ram is TypeORM supposed to consume? I'm getting an OOM at 2GB with no data during startup, but I don't have a profiler and I really didn't expect to need one this early.
    hey guys, i have this error QueryFailedError: insert or update on table "role_users_user" violates foreign key constraint "FK_ed6edac7184b013d4bd58d60e54" and i can't wrap my head around it. all i'm doing is inserting an email to the database
    2 replies
    Hello everybody, maybe Somebody has this warning in typeorm? How it fix?
    Deprecated as of 10.7.0. highlight(lang, code, ...args) has been deprecated. Deprecated as of 10.7.0. Please use highlight(code, options) instead.highlightjs/highlight.js#2277
    MongoDB Typeorm: as $ lookup works with typeorm, it doesn't return data like it would from console
    Justin Levi Winter

    Hi all, I'm new to typeorm but I'm seeing a very strange issue with the synchronize: true functionality when I modify an entity with a ManytoMany relationship. In short, any data that is in the join table before making the entity change, is gone after.

    Here is my Project Entity

    export class Project extends BaseEntity {
      @Field(() => Int)
      id: number;
      name: string;
      @Field({ nullable: true })
      @Column("text", { nullable: true })
      cluster?: string;
      @ManyToMany((type) => Group, (group) => group.projects, { lazy: true })
      @Field((type) => [Group], { nullable: true })
      groups?: Group[];

    Here is my Group Entity

    export class Group extends BaseEntity {
      @Field(() => String)
      id: string;
      name: string;
      @Field({ nullable: true })
      type: string;
      @Field({ nullable: true })
      @Column("text", { nullable: true })
      currency: string;
      @Field((type) => [Project])
      @ManyToMany((type) => Project, (project) => project.groups, { lazy: true })
      projects: Project[];
      @ManyToMany((type) => Modifier, (modifier) => modifier.group, { lazy: true })
      @Field((type) => [Modifier])
      modifiers: Modifier[];

    If I add a new field to either the Group or the Project, the migration is automatically run and the following queries

    query: CREATE TABLE "temporary_project" ("id" integer PRIMARY KEY NOT NULL, "name" text NOT NULL, "cluster" text, "asdfa" text)
    query: INSERT INTO "temporary_project"("id", "name", "cluster") SELECT "id", "name", "cluster" FROM "project"
    query: DROP TABLE "project"
    query: ALTER TABLE "temporary_project" RENAME TO "project"
    The project_groups_group table has data before, and is empty after the migration is finished
    Wondering why the migration would impact the join table as I'm not seeing any query that would even update that?
    Justin Levi Winter
    I posted a working example here:

    How to get count and num of relation.

    but it's not work

    Noda Hikaru
    Hi Everyone.
    Is there any way to select only few related table columns with find() method?
    Hi Everyone.
    I have a question on Stackoverflow, please have a look and help me. Thank you
    Hi guys, Who knows how to make the order of fields in database consistent with the order of attribute declaration in entity?
    I have a question ,plz have a look and help,thank you
    Hi coders, is there anyway to make a column type have a default transformer other than creating a custom one and adding it to all columns needed
    John Munson

    Does anyone know if it's possible to set a field to null using the save method? Is there some fancy trick that I'm unaware of? Do I need to use some sort of helper function like IsNull when you're working with the find methods?

    For example...

    // Let's find Jeff and get rid of his stupid middle name
    const jeff = await userRepository.findOne({firstName: 'Jeff'})
    jeff.middleName = null
    await userRepository.save(jeff)
    // Doesn't work... Jeff still has a middle name
    I know I could use the update method to accomplish this, but my use case is dependent on the TypeORM events/subscribers system, and update unfortunately does not work with the event system
    Tristan Blackwell

    Using TypeOrm for the first time against an already existing schema, the table names are plural and PascalCase and the entities should be singular. Therefore I'm using

    export class AccessLog {

    To define the entity. When I run migrate:generate it generates a change script that tries to create that Table AccessLogs even though it already exists.

    If I change the table name to lowercase:

    export class AccessLog {

    the problem goes away - but then the mapping in the Entity decorator is wrong and a newly created database with these migrations with generate the lowercase table name, which won't match all the other existing instances of the database. Surely I can't be the first person who doesn't have lowercase or snake_case table names?

    Sagid M
    How to save an entity that has OneToMany relation?
    I am setting it approximately like so
    const phones = [getRepository(Phone).create({model: 'iPhone'})];
    getRepository(Owner).save({name: 'Alex', phones})
    // insert into owners ... OK!
    // but there is no insert into phones, so Alex is created without phones
    @sagidM because that phones variable is not yet inserted in the database , as mentioned in the docs .create only creates an instance it doesnt write it to the database , change it to .save and you'll have it .
    Martin Mok

    Hi all, our team encounter a problem when using
    @BeforeInsert() and @BeforeUpdate().

    export class Ngo {
    @Column('jsonb', { nullable: true })
        onboardingData?: NgoOnboardingData;
        profileUpdated: boolean;
    @OneToOne(() => NgoProfile, (ngoProfile) => ngoProfile.ngo, {
            eager: true,
            cascade: true,
        ngoProfile: NgoProfile;
    setProfileUpdated() {
        const updatedAtDate = this.ngoProfile.updatedAt,
                reviewedAtDate = this.ngoProfile.reviewedAt,
                unpublishedAtDate = this.ngoProfile.unpublishedAt;
        if (
                (this.onboardingData?.status?.profileEditCompleted ?? true) &&
                (!reviewedAtDate || reviewedAtDate < updatedAtDate) &&
                (!unpublishedAtDate || unpublishedAtDate < updatedAtDate)
        ) {
                this.profileUpdated = true;
        } else {
                this.profileUpdated = false;

    We found out that when saving the ngo using Repository.save, the setProfileUpdated() was not triggered.
    How to handle this case in TypeORM?

    Sagid M
    @ghaedi1993 that's what I am saying. The other frameworks save the relation accordingly like Entity Framework (.NET), Active Records (Ruby), or Django

    hey all, I'm getting this error I cannot for the life of me figure out. I didn't create this schema FYI.

    I have a table called 'view' and it has a column named 'url'

    my entity looks like

    @Entity({ name: "view" })
    export class View extends BaseEntity implements IView {
        public url?: string;

    and I postgresql describe the table and I see the url column in the table, but i'm getting this error

    QueryFailedError: column View.url does not exist
    Hi everyone, I just recently started using typeorm (with NestJS). Been trying to get migrations working, it's been a struggle. migrations files are generated but when I try to run them, I get No migrations are pending and the migration table is empty. Does anybody have pointers to help with this?
    Never mind, fixed it... src vs dist issue.
    Jorge Andrade
    Error: A circular dependency has been detected (property key: "_id"). Please, make sure that each side of a bidirectional relationships are using lazy resolvers ("type: () => ClassType").
    Is it possible to set type for an entity?
      public _id: ObjectID;
    Hey, folks. Do you have a that helps to keep nestJs app alive on initial connection fail? Default configuration with nestjs/typeorm package allows to define retry counter, but after a few efforts application just dies. I want to keep DB-independent endpoints in work condition.
    How to specify the field location when adding table fields through migration
    Maciej Maciaszek
    Hi, I have problem with clearing many-to-many on an entity: project.users = []; await this.projectsRepository.save(project);. Relations are not deleted.
    Hi, I have a system where has been used create to generate migrations. Now if I try to instead generate one I have an infinite list of changes, not only my change. Is there a way to make typeorm ignore all the changes that are already applied via create?
    I would like to re align it because it seems that typeorm doesn't know the state of the db anymore
    Martin Mok
    TypeORM enum doesn't set the Postgesql data type to enum, any work around?
    Matt J
    We have a column (encoded_sequence mediumint unsigned not null) that gets populated by a "BEFORE INSERT" trigger in our MySQL DB and I'm having a hard time figuring out how to map it properly in the @Entity so that inserts work. I've achieved some success by adding "default: true" to the @Column annotation options. However, unless we supply the entity with that column set to null, we get "Database error code: 1364. Message: Field 'encoded_sequence' doesn't have a default value"". This certainly appears to be a DB error, however we can successfully run insert queries with the column omitted. I've also been able to overcome this by adding a default value in the database, but as per our business rules, that is not very safe. I'm hoping there is a "nice" way to do this properly.

    Hi!! is there anyway to trigger soft deletes in subscriber?
    since it's updating the deletedAt column im using beforeUpdate and for the event type i tested UpdateEvent and RemoveEvent both
    when i do a patch request everything is working fine but when it comes to delete request method both event.databaseEntity and event.entity will be undefined

    hard delete is working just fine but soft delete.... any suggestion?

    such a dead community :)
    Andrii Lotysh
    Hello everyone! Smb know how to create query which return users which have into column languages not empty array?
    this in queryBuilder

    Hi have a problem with typeorm, I opened a question on stackoverflow here https://stackoverflow.com/questions/67960062/typeorm-type-entity-is-not-assignable-to-type-querydeeppartialentityent

    Any help is appreciated