我对TypeOrm相当陌生,我正在尝试将它用于一个项目,但我在生成迁移时面临问题。我有一个Postgres应用程序运行在我的本地在端口5432。
我的实体看起来是这样的
@Entity()
export class User {
@PrimaryGeneratedColumn()
id!: number;
@Index({ unique: true })
@Column('text', {nullable:true})
username!: string;
@Index({ unique: true })
@Column('text', {nullable:true})
@IsEmail()
email!: string;
@Index()
@Column('bool',{nullable:true, default: false})
emailVerified!: boolean;
@UpdateDateColumn()
@IsDate()
updateDate!: Timestamp;
@Column('text',)
about!: string;
};
我的OrmConfig看起来像这样
{
"entities": ["src/entity/*.js"],
"migrations": ["src/migration/*.js"],
"subscribers": ["src/subscriber/**/*.js"],
"cli": {
"migrationsDir": "src/migration",
"entitiesDir": "src/entities",
"subscribersDir": "src/subscriber"
},
"url": "postgres://@0.0.0.0:5432/nftme_dev",
"type": "postgres",
"synchronize": true
}
当我跑步时:
yarn run typeorm migration:generate -n initial
它抛出一个错误,上面写着:
$ node_modules/.bin/typeorm migration:generate -n initial
No changes in database schema were found - cannot generate a migration. To create a new empty migration use "typeorm migration:create" command```
发布于 2022-03-31 17:04:54
因此,在调试了一天之后,我终于能够将它确定下来。
因此,当我使用synchronize: true
选项时,已经为数据库中的实体创建了模式,当我试图生成它时失败了,因为没有什么改变。
我创建了一个新的db,并试图生成迁移,它成功了。
发布于 2022-02-25 07:36:17
TypeORM提供了如此多的可能性,因此很容易迷失其中。;-)
您可以修改本地数据库并生成迁移文件:
typeorm migration:generate -n UserMigration
您可以修改实体并同步更改:(您需要这样做)
https://stackoverflow.com/questions/71261951
复制相似问题