Typeorm迁移:没有唯一的约束

时间:2019-12-09 12:43:26

标签: postgresql nestjs typeorm

我与像这样构造的typeor有很多关系:

PostEntity 类中

@PrimaryGeneratedColumn('uuid')
id: string;
@ManyToOne(type => UserEntity, user => user.posts)
userPosted: UserEntity;

UserEntity

@PrimaryGeneratedColumn('uuid')
id: string;
@OneToMany(type => PostEntity, c => c.userPosted)
posts: PostEntity[];

我可以成功创建迁移,但是当我尝试运行迁移时会引发错误:

  

查询失败:ALTER TABLE“ post”添加约束   “ FK_f36f38b0231a9075541aae12b73”外键(“ user_posted_id”)   参考“ user”(“ id”)ON删除无操作更新无操作错误:   {错误:没有唯一的约束匹配给定的键   引用表“用户”

我只是关注文档。不知道为什么迁移不会在数据库中更新。 迁移文件:https://gist.github.com/DooMachine/fe6a34817ed763941d74097acd4a4efd

0 个答案:

没有答案