You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import { Entity, PrimaryKey, Property } from "@mikro-orm/core";
@Entity()
export class Post {
@PrimaryKey()
id!: number;
@Property({ type: "date" })
createdAt: Date = new Date();
@Property({ type: "date", onUpdate: () => new Date() })
updatedAt: Date = new Date();
@Property({ type: "text" })
title!: string;
}
and this code in my index.ts file
import { MikroORM } from "@mikro-orm/core";
import { Post } from "./entities/Post";
import microConfig from "./mikro-orm.config";
const main = async () => {
const orm = await MikroORM.init(microConfig);
await orm.getMigrator().up();
const post = orm.em.create(Post, { title: "my frist post" });
await orm.em.persistAndFlush(post);
};
main()
After creating the migration with npx mikro-orm migration:create
I get the following migration
import { Migration } from "@mikro-orm/migrations";
export class Migration20210222221432 extends Migration {
async up(): Promise<void> {
this.addSql(
'alter table "post" drop constraint if exists "post_id_check";'
);
this.addSql(
'alter table "post" alter column "id" type serial primary key using ("id"::serial primary key);'
);
}
}
and when I try to run my index.ts file I get this error
SyntaxErrorException: alter table "post" alter column "id" type serial primary key using ("id"::serial primary key); - syntax error at or near "primary"
The text was updated successfully, but these errors were encountered:
That code would not create such migration on its own - you had to have the column defined before wrongly - your problematic migration is an alter statement.
In other words, this is not enough to replicate it.
Moreover, this sounds more like a knex issue, as that is where the actual query gets generated (and where the problematic type casting happens).
Migrations are made this way so you have absolute control - so to work this around, fix the query manually in the generated file.
This commit introduces new schema diffing capabilitites. Instead of shared code for
creating and altering tables, we now build schema objects from entities and existing
schema, and compare those (this will later allow to create down migrations too).
- Better mapping - adds mapped types to abstract most of the column types (e.g. { type: t.decimal })
- FK diffing
- Proper index diffing (before we compared just names)
- Custom index expressions
- Comment diffing
- Column length diffing (e.g. numeric(10,2) or varchar(100))
- Changing PK types
- Schena/namespace diffing (posgtres only)
Closes#1486Closes#1518Closes#579Closes#1559Closes#1602Closes#1480Closes#1687
Describe the bug
I have the following entity
and this code in my index.ts file
After creating the migration with
npx mikro-orm migration:create
I get the following migration
and when I try to run my index.ts file I get this error
The text was updated successfully, but these errors were encountered: