gpt4 book ai didi

java - 添加外键(Lquidbase)

转载 作者:行者123 更新时间:2023-12-02 08:42:00 24 4
gpt4 key购买 nike

我正在尝试添加一个外键,该外键将引用另一个表中的主键,并且该主键将位于 user_id 列中,但由于某种原因,我收到语法异常

 <changeSet id="add-export_users-table" author="artjom.prozorov">
<preConditions>
<not>
<tableExists tableName="export_users"/>
</not>
</preConditions>
<createSequence sequenceName="export_users_id_seq"/>
<createTable tableName="export_users">
<column name="id" type="BIGINT"/>
<column name="user_id"/>
</createTable>
<addNotNullConstraint tableName="export_users" columnName="id"/>
<addPrimaryKey tableName="export_users" columnNames="id"/>
<addForeignKeyConstraint baseTableName="export_users" baseColumnNames="user_id" constraintName="export_users_fk"
referencedTableName="users"
referencedColumnNames="user_id"/>



Export class
@OneToOne
@JoinColumn(name = "user_id")
private UserEntity userEntity;

UserEntity class
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "user_id_seq")
@SequenceGenerator(name = "user_id_seq", sequenceName = "public.user_id_seq", allocationSize = 0)
private Long id;

最佳答案

<addForeignKeyConstraint baseTableName="export_users"
baseColumnNames="user_id"
constraintName="export_users_fk"
referencedTableName="users"
referencedColumnNames="user_id"/>

假设users表的ID是user_id,但由于我在您的UserEntity @Id上没有看到任何注释,我假设它的ID 更简单地称为id

关于java - 添加外键(Lquidbase),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61325239/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com