GuiwenChen opened a new issue, #34180: URL: https://github.com/apache/shardingsphere/issues/34180
## Bug Report ### Which version of ShardingSphere did you use? ShardingSphere-JDBC 5.5.1、Springboot 2.2.1、mysql-connector-java 8.0.16 ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy? ShardingSphere-JDBC ### Expected behavior Added when no foreign key constraint exists ### Actual behavior The "alter table xxx add constraint xxx foreign key xxx" command is executed each time ### Reason analyze (If you can) For example, the logical table 'orders' is sharded into' orders_0 'and' orders_1 '. The problem appears to be executing "SHOW CREATE TABLE 'db'. 'orders' ". Foreign key constraint information cannot be found because the logical table does not exist. ### Steps to reproduce the behavior application.properties: `spring.datasource.initialization-mode=always` `spring.jpa.hibernate.ddl-auto=update` Entity Orders: `@Entity(name = "ORDERS")` `public class Orders {` `@OneToOne` `private EntityCustomer customer;` `}` According to the Settings, each time the program is started, the system checks whether the Entity is consistent with the physical table structure。 Through the breakpoint debugging, I found that the problem seems to appear in the `com.mysql.cj.jdbc.DatabaseMetaData.java#extractForeignKeyFromCreateTable` method. Execute the database query statement :`SHOW CREATE TABLE 'db'. 'orders'`, because the table does not exist, the foreign key constraint information cannot be queried. Because of this, the sql statement that adds the foreign key constraint is executed each time. And because the foreign key constraint already exists, an error is reported each time, as follows: `org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table orders add constraint FKxxxxx foreign key (xxx, xxx) references customer (xxx, xxx)" via JDBC Statement` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@shardingsphere.apache.org.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org