#Unable to use autoLoadEntity in MikroOrm

4 messages · Page 1 of 1 (latest)

west atlas
#

I was recently trying to move from typeorm to mikroorm but I am unable to use the feature where entity will be automatically created, there are no errors but it is not reflected on db/schema/table,
Can anyone tell me what I am doing wrong.

You can see the structure of my app as shown in photo

  1. Here is My User Entity ( src/user/user.entity.ts)
import { Entity, PrimaryKey, Property } from '@mikro-orm/core';

@Entity()
export class User {
  @PrimaryKey()
  id: number;

  @Property()
  name: string;
}
  1. Here is my User Module where I imported the entity ( src/user/user.module.ts)
import { MikroOrmModule } from '@mikro-orm/nestjs';
import { Module } from '@nestjs/common';
import { User } from './user.entity';

@Module({
  imports: [MikroOrmModule.forFeature([User])],
})
export class UserModule {}
  1. And here is my app.module.ts (src/app.module.ts)
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UserModule } from './user/user.module';
import { ConfigModule } from '@nestjs/config';
import { MikroOrmModule } from '@mikro-orm/nestjs';
import { PostgreSqlDriver } from '@mikro-orm/postgresql';
import env from './env';

@Module({
  imports: [
    ConfigModule.forRoot(),
    MikroOrmModule.forRoot({
      dbName: 'mikro-orm-testing',
      driver: PostgreSqlDriver,
      clientUrl: env.DATABASE_URL,
      autoLoadEntities: true,
      ensureDatabase: true,
    }),
    UserModule,
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
#

Unable to use autoLoadEntity in MikroOrm

#

You can see here also no error is being detected

keen ice
#

but it is not reflected on db/schema/table
Do you mean you want to apply the entity you created in the code to the database by executing a query?