我有一个名为CustomizationSet的表,其中包含以下列:
customization_set_guid (which is a non-nullable guid and also the primary key)
creator_account_guid
and a few others
还有一个带有现有数据的表 Registration,包含以下列:
registration_id (an int and the primary key)
customization_set_guid (also a guid (so a char(36)) which is nullable, and all entries are currently null)
and a few other columns
当我尝试运行时
ALTER TABLE Registration ADD FOREIGN KEY
(
customization_set_guid
) REFERENCES CustomizationSet (
customization_set_guid
);
在MySQL Workbench中,它会显示错误1050Table '.\dbname\registration' already exists.
如果我尝试使用“Alter Table Dialog”的Foreign Keys选项卡来添加外键,并选择CustomizationSet作为参考表,它不允许我在列列表中选择customization_set_guid。
我真的不确定为什么它不允许我添加这个外键。我刚刚成功地在刚刚添加的表之间创建了外键。Registration表已经存在一段时间了...
ALTER TABLE Registration DROP FOREIGN KEY MyConstraintName
,然后添加外键ALTER TABLE Registration ADD FOREIGN KEY...
。 - Arya