MySQL Forums
Forum List  »  NDB clusters

Re: Cannot add unique constraint with fk column
Posted by: Martin Sköld
Date: June 17, 2015 11:46AM

Actually there seems to be a problem with the ADD CONSTRAINT (will create a bug). This is equivalent to what you want to do and more efficient:
mysql> CREATE TABLE networks (
-> tenant_id VARCHAR(255),
-> id VARCHAR(36) NOT NULL,
-> name VARCHAR(255),
-> status VARCHAR(16),
-> admin_state_up BOOL,
-> shared BOOL,
-> PRIMARY KEY (id)
-> );
Query OK, 0 rows affected (0,68 sec)
mysql> CREATE TABLE ports (
-> tenant_id VARCHAR(255),
-> id VARCHAR(36) NOT NULL,
-> name VARCHAR(255),
-> network_id VARCHAR(36) NOT NULL,
-> mac_address VARCHAR(32) NOT NULL,
-> admin_state_up BOOL NOT NULL,
-> status VARCHAR(16) NOT NULL,
-> device_id VARCHAR(255) NOT NULL,
-> device_owner VARCHAR(255) NOT NULL,
-> PRIMARY KEY (id)
-> );
Query OK, 0 rows affected (0,90 sec)
mysql> CREATE UNIQUE INDEX uniq_ports0network_id0mac_address on ports (network_id, mac_address);
Query OK, 0 rows affected (0,82 sec)
mysql> ALTER TABLE ports ADD FOREIGN KEY(network_id) REFERENCES networks (id);
Query OK, 0 rows affected (0,50 sec)
Records: 0 Duplicates: 0 Warnings: 0

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: Cannot add unique constraint with fk column
683
June 17, 2015 11:46AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.