gpt4 book ai didi

mysql - 在maven pom中使用addForeignKeyConstraint + liquibase

转载 作者:行者123 更新时间:2023-11-29 21:30:19 25 4
gpt4 key购买 nike

我需要使用 liquibase 创建下表,但出现以下错误。有人可以帮我找出其中的问题吗?我是 DB 和 liquibase 的新手。

<changeSet author="mohan" id="table-for-users-roles">
<createTable tableName="USERS">
<column name="ID" type="NUMBER(19,0)" >
<constraints nullable="false" primaryKey="true" primaryKeyName="PK_USERS"/>
</column>
<column name="NAME" type="VARCHAR2(10)" remarks="User name"></column>
<column name="PASSWORD" type="VARCHAR2(10)" remarks="Password"></column>
</createTable>

<createTable tableName="ROLES">
<column name="ID" type="NUMBER(19,0)" >
<constraints nullable="false" primaryKey="true" primaryKeyName="PK_ROLES"/>
</column>
<column name="NAME" type="VARCHAR2(10)" remarks="Role name"></column>
</createTable>

<createTable tableName="USER_ROLES">
<column name="USER_ID" type="NUMBER(19,0)" >
<constraints nullable="false" primaryKey="true" primaryKeyName="PK_USER_ROLES"/>
</column>
<column name="ROLE_ID" type="NUMBER(19,0)">
<constraints nullable="false" primaryKey="true" primaryKeyName="PK_USER_ROLES"/>
</column>
</createTable>

<addForeignKeyConstraint constraintName="FK_USERS" baseColumnNames="ID" baseTableName="USERS" referencedTableName="USER_ROLES" referencedColumnNames="USER_ID" />

<addForeignKeyConstraint constraintName="FK_ROLES" baseColumnNames="ID" baseTableName="ROLES" referencedTableName="USER_ROLES" referencedColumnNames="ROLE_ID" />
</changeSet>

这是错误:

SEVERE 2/10/16 10:32 AM: liquibase: change-logs/wm-db-changelog-master.xml: change-logs/1.0/wm-db-changelog-1.0.xml::table-for-users-roles::mohan: Change Set change-logs/1.0/wm-db-changelog-1.0.xml::table-for-users-roles::mohan failed.  Error: ORA-02270: no matching unique or primary key for this column-list
[Failed SQL: ALTER TABLE USERS ADD CONSTRAINT FK_USERS FOREIGN KEY (ID) REFERENCES USER_ROLES (USER_ID)] liquibase.exception.DatabaseException: ORA-02270: no matching unique or primary key for this column-list
[Failed SQL: ALTER TABLE USERS ADD CONSTRAINT FK_USERS FOREIGN KEY (ID) REFERENCES USER_ROLES (USER_ID)]
at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:301)

提前致谢!

最佳答案

不要在单个变更集中运行所有这些变更,而是将它们分成至少两个变更集。具体来说,我将在第二个变更集中将 USERS 和 ROLES 表相互关联的变更分开。

关于mysql - 在maven pom中使用addForeignKeyConstraint + liquibase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35319480/

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