ICannerxy opened a new issue #15873:
URL: https://github.com/apache/shardingsphere/issues/15873


   ## Bug Report
   
   ### Which version of ShardingSphere did you use?
   
   - 5.1.0
   
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   
   - ShardingSphere-Proxy
   
   ### Expected behavior
   
   
![image](https://user-images.githubusercontent.com/40480377/157192481-8d8f79b5-325f-420c-87f9-174243c1b251.png)
   
   Successfully created a table .
   
   ### Actual behavior
   
   
![image](https://user-images.githubusercontent.com/40480377/157192705-6cd8427e-f9b3-4003-916e-713b3ec3228c.png)
   
   Create a table failed.
   
   ### Reason analyze (If you can)
   
   The foreign key in a database in mysql cannot be repeated, When generating 
SQL execution statements, there is not rewrite foreign key name.
   
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule 
configuration, when exception occur etc.
   
   1. add rules
   ```yaml
     ds_0:
       url: 
jdbc:mysql://localhost:3306/demo_ds_0?serverTimezone=UTC&useSSL=false
       username: root
       password: servyou
       connectionTimeoutMilliseconds: 30000
       idleTimeoutMilliseconds: 60000
       maxLifetimeMilliseconds: 1800000
       maxPoolSize: 50
       minPoolSize: 1
       dataSourceClassName: com.zaxxer.hikari.HikariDataSource
     ds_1:
       url: 
jdbc:mysql://localhost:3306/demo_ds_1?serverTimezone=UTC&useSSL=false
       username: root
       password: servyou
       connectionTimeoutMilliseconds: 30000
       idleTimeoutMilliseconds: 60000
       maxLifetimeMilliseconds: 1800000
       maxPoolSize: 50
       minPoolSize: 1
       dataSourceClassName: com.zaxxer.hikari.HikariDataSource
   ```
   
   ```yaml
   - !SHARDING
     bindingTables:
     - t_order,t_order_item
     defaultDatabaseStrategy:
       standard:
         shardingAlgorithmName: database_inline
         shardingColumn: user_id
     defaultTableStrategy:
       none: ''
     keyGenerators:
       snowflake:
         type: SNOWFLAKE
     shardingAlgorithms:
       database_inline:
         props:
           algorithm-expression: ds_${user_id % 2}
         type: INLINE
       t_order_inline:
         props:
           algorithm-expression: t_order_${order_id % 2}
         type: INLINE
       t_order_item_inline:
         props:
           algorithm-expression: t_order_item_${order_id % 2}
         type: INLINE
     tables:
       t_order:
         actualDataNodes: ds_${0..1}.t_order_${0..1}
         keyGenerateStrategy:
           column: order_id
           keyGeneratorName: snowflake
         logicTable: t_order
         tableStrategy:
           standard:
             shardingAlgorithmName: t_order_inline
             shardingColumn: order_id
       t_order_item:
         actualDataNodes: ds_${0..1}.t_order_item_${0..1}
         keyGenerateStrategy:
           column: order_item_id
           keyGeneratorName: snowflake
         logicTable: t_order_item
         tableStrategy:
           standard:
             shardingAlgorithmName: t_order_item_inline
             shardingColumn: order_id
   ```
   2. create table `t_order_item`
   ```java
   CREATE TABLE `t_order_item` (
     `order_id` bigint(32) NOT NULL,
     `user_id` int(11) DEFAULT NULL,
     `item_name` varchar(255) DEFAULT NULL,
     `order_item_id` bigint(32) DEFAULT NULL,
     PRIMARY KEY (`order_id`),
     CONSTRAINT `fk_order_id` FOREIGN KEY (`order_id`) REFERENCES `t_order` 
(`order_id`)
   ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
   ```
   
   ### Example codes for reproduce this issue (such as a github link).
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to