-
-
Notifications
You must be signed in to change notification settings - Fork 610
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
Migrations do not respect table scheme.
Stack trace
TableExistsException: create table "test"."DEVICES" ("ID" serial primary key, "TOKEN" varchar(255) not null); - relation "DEVICES" already exists
at PostgreSqlExceptionConverter.convertException (/home/virchenko/Projects/phyapi/node_modules/@mikro-orm/postgresql/PostgreSqlExceptionConverter.js:38:24)
at PostgreSqlDriver.convertException (/home/virchenko/Projects/phyapi/node_modules/@mikro-orm/core/drivers/DatabaseDriver.js:171:54)
at /home/virchenko/Projects/phyapi/node_modules/@mikro-orm/core/drivers/DatabaseDriver.js:175:24
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at Function.runSerial (/home/virchenko/Projects/phyapi/node_modules/@mikro-orm/core/utils/Utils.js:458:22)
at MigrationRunner.run (/home/virchenko/Projects/phyapi/node_modules/@mikro-orm/migrations/MigrationRunner.js:17:13)
To Reproduce
Steps to reproduce the behavior:
- Create an entity, for example:
import { Entity, PrimaryKey, Property } from '@mikro-orm/core';
@Entity({
tableName: 'test.DEVICES',
})
export class Device {
@PrimaryKey({ fieldName: 'ID', type: 'number' })
id!: number;
@Property({ fieldName: 'TOKEN' })
token!: string;
}
- Generate a migration:
npx mikro-orm migration:create
where output will be like this:
import { Migration } from '@mikro-orm/migrations';
export class Migration20201201130518 extends Migration {
async up(): Promise<void> {
this.addSql('create table "test"."DEVICES" ("ID" serial primary key, "TOKEN" varchar(255) not null);');
}
}
- Apply the migration:
npx mikro-orm migration:up
- Generate a new migration:
npx mikro-orm migration:create
where output will be the same:
import { Migration } from '@mikro-orm/migrations';
export class Migration20201201130522 extends Migration {
async up(): Promise<void> {
this.addSql('create table "test"."DEVICES" ("ID" serial primary key, "TOKEN" varchar(255) not null);');
}
}
- Apply the migration:
npx mikro-orm migration:up
Expected behavior
Correct migrations:
- first migration with "create scheme 'test';" statement and down() method;
- second migration must be empty.
Versions
| Dependency | Version |
|---|---|
| node | v12.20.0 |
| typescript | 4.0.5 |
| mikro-orm | 4.3.0 |
| PostgreSQL | 13.1 |
lexxorlov and dimitu
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working