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
Adding a OneToOne to an existing schema creates a invalid migration file that first adds the column then tries to add it again
Stack trace
DriverException: alter table `user` add column `profile_id` varchar not null; - SQLITE_ERROR: Cannot add a NOT NULL column with default value NULL
at SqliteExceptionConverter.convertException (C:\repro\.yarn\$$virtual\@mikro-orm-core-virtual-a47c7ffdac\0\cache\@mikro-orm-core-npm-4.2.1-157e5819c7-1bb1c1779c.zip\node_modules\@mikro-orm\core\platforms\ExceptionConverter.js:8:16)
at SqliteExceptionConverter.convertException (C:\repro\.yarn\$$virtual\@mikro-orm-sqlite-virtual-c27b82c743\0\cache\@mikro-orm-sqlite-npm-4.2.1-9331d09dc8-76e194b3f5.zip\node_modules\@mikro-orm\sqlite\SqliteExceptionConverter.js:46:22)
at SqliteDriver.convertException (C:\repro\.yarn\$$virtual\@mikro-orm-core-virtual-a47c7ffdac\0\cache\@mikro-orm-core-npm-4.2.1-157e5819c7-1bb1c1779c.zip\node_modules\@mikro-orm\core\drivers\DatabaseDriver.js:168:54)
at C:\repro\.yarn\$$virtual\@mikro-orm-core-virtual-a47c7ffdac\0\cache\@mikro-orm-core-npm-4.2.1-157e5819c7-1bb1c1779c.zip\node_modules\@mikro-orm\core\drivers\DatabaseDriver.js:172:24
at Function.runSerial (C:\repro\.yarn\$$virtual\@mikro-orm-core-virtual-a47c7ffdac\0\cache\@mikro-orm-core-npm-4.2.1-157e5819c7-1bb1c1779c.zip\node_modules\@mikro-orm\core\utils\Utils.js:457:22)
at C:\repro\.yarn\$$virtual\@mikro-orm-migrations-virtual-5fb7d99af2\0\cache\@mikro-orm-migrations-npm-4.2.1-510440861c-2f6443fc3a.zip\node_modules\@mikro-orm\migrations\MigrationRunner.js:23:17
To Reproduce
import'reflect-metadata';import{Entity,MikroORM,PrimaryKey,OneToOne}from'@mikro-orm/core';asyncfunctioncreateAndRunMigration(entities: any[]){constdb=awaitMikroORM.init({type: 'sqlite',entities: entities,dbName: __dirname+'/db.sqlite',migrations: {path: __dirname+'/migrations',},});awaitdb.getMigrator().createMigration();awaitdb.getMigrator().up();awaitdb.close();}
@Entity({tableName: 'profile'})classProfile{
@PrimaryKey()id: string;}
@Entity({tableName: 'user'})classUser{
@PrimaryKey()id: string;}
@Entity({tableName: 'user'})classUser2{
@PrimaryKey()id: string;
@OneToOne(()=>Profile)profile: Profile;}(async()=>{awaitcreateAndRunMigration([User,Profile]);awaitnewPromise((resolve)=>{setTimeout(resolve,2000);});// Simulates adding `profile` to the User entityawaitcreateAndRunMigration([User2,Profile]);})();
Expected behavior
The migration to be valid or an error to be thrown if i'm configuring the relationships incorrectly
Additional context
The migration created
this.addSql('alter table `user` add column `profile_id` varchar not null;');this.addSql('create index `user_profile_id_index` on `user` (`profile_id`);');this.addSql('create unique index `user_profile_id_unique` on `user` (`profile_id`);');this.addSql('alter table `user` add column `profile_id` varchar null;');this.addSql('create index `user_profile_id_index` on `user` (`profile_id`);');this.addSql('create unique index `user_profile_id_unique` on `user` (`profile_id`);');
Versions
Dependency
Version
node
v12.19.0
typescript
4.0.3
@mikro-orm/core
4.2.1
@mikro-orm/migrations
4.2.1
@mikro-orm/sqlite
4.2.1
The text was updated successfully, but these errors were encountered:
I don't think this is a good way to simulate adding a property. You have two entities loaded, the dump looks exactly like that - 3 statements for each entity. Each entity is checked for diff, there is no grouping based on table name. But the output is weird for sure...
edit: I see, now I get it, you register only the User2 for the second time...
Describe the bug
Adding a OneToOne to an existing schema creates a invalid migration file that first adds the column then tries to add it again
Stack trace
To Reproduce
Expected behavior
The migration to be valid or an error to be thrown if i'm configuring the relationships incorrectly
Additional context
The migration created
Versions
The text was updated successfully, but these errors were encountered: