Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我们是否可以在typeorm/hibernate中命名一个关系映射,以便在抛出错误时,在读取/理解错误时更有意义?_Hibernate_Typeorm - Fatal编程技术网

我们是否可以在typeorm/hibernate中命名一个关系映射,以便在抛出错误时,在读取/理解错误时更有意义?

我们是否可以在typeorm/hibernate中命名一个关系映射,以便在抛出错误时,在读取/理解错误时更有意义?,hibernate,typeorm,Hibernate,Typeorm,我有两个实体user和student,这两个实体之间有一个onetoone映射,具体取决于user。当我试图在student中创建一个在user中没有映射记录的记录时,它会出现如下错误- [Nest] 4040 - 06/28/2020, 4:06:36 PM [ExceptionsHandler] insert or update on table "student" violates foreign key constraint "FK_8231416a

我有两个实体
user
student
,这两个实体之间有一个
onetoone
映射,具体取决于
user
。当我试图在student中创建一个在
user
中没有映射记录的记录时,它会出现如下错误-

[Nest] 4040   - 06/28/2020, 4:06:36 PM   [ExceptionsHandler] insert or update on table "student" violates foreign key constraint "FK_8231416aa588b99afce55d26032" +130ms
QueryFailedError: insert or update on table "student" violates foreign key constraint "FK_8231416aa588b99afce55d26032"
我想知道是否有可能在实体中命名
onetoone
关系,使此错误变得更有意义,类似于-
usernameFKContracint
而不是
FK\u 8231416A5588B99AFCE55D26032

这是我在实体中拥有的-

@OneToOne(() => User, { nullable: false })
  @JoinColumn({
    name: 'userName',
    referencedColumnName: 'userName',
  })
  user: User;

对。删除表格并用以下内容注释
OneToOne

@ForeignKey(name="your_constraint_name")

基本上,如果您让JPA创建表,您可以自定义表名、列名、外键列名、联接表名(如果使用)、任何约束名

确切位置?像
@ForeignKey(name=“your_constraint_name”)@OneToOne(()=>User,{nullable:false})
?是的。就在您的
@OneToOne
注释上方。谢谢。我将在一段时间内尝试它,因为数据将消失。在此之前需要测试一些东西。似乎,
typeorm
中没有此注释。对此有什么建议吗?在typeorm
@JoinColumn({constraintName:'fk\u post\u author\u id')中可能是这样的