this is User entity:
import { Entity, PrimaryKey, Property } from "@mikro-orm/core";
import { ObjectType, Field } from "type-graphql";
@ObjectType()
@Entity()
export class User {
@Field()
@PrimaryKey()
id!: number;
@Field(() => String)
@Property({ type: "date" })
createdAt = new Date();
@Field(() => String)
@Property({ type: "date", onUpdate: () => new Date() })
updatedAt = new Date();
@Field()
@Property({ type: "text", unique: true })
username!: string;
@Field()
@Property({ type: "text", unique: true })
email!: string;
@Property({ type: "text" })
password!: string;
}
this is the migration script:
"create:migration": "mikro-orm migration:create"
I already had username and password column but when I tried to add "email" column, migration runs successfully but it does not reflected in database. This is the migration result:
export class Migration20210608151159 extends Migration {
async up(): Promise<void> {
this.addSql('alter table "user" add column "email" text not null;');
this.addSql('alter table "user" add constraint "user_email_unique" unique ("email");');
}
}
I refresh table but do not see email column. When I send client request I get this error:
error: insert into "user" as "e0" ("created_at", "email", "password", "updated_at", "username") values ($1, $2, $3, $4, $5) returning * - column "email" of relation "user" does not exist
When I run npx mikro-orm migration:up this time I get this message:
"DriverException: alter table "user" add column "email" text not null; - column "email" of relation "user" already exists"
somehow migration is not modifying the database