"表中不存在属性 ID



正在努力了解向Agents表添加外键的问题所在。我得到了错误";PropertyID在表"中不存在;。以下是相关代码:

CREATE TABLE Properties (
PropertyID INT(8),
Address VARCHAR(50) NOT NULL,
Level TINYINT(1) NOT NULL,
PropertyValue INT(10) NOT NULL,
CONSTRAINT PRIMARY KEY (PropertyID)
);
CREATE TABLE Agents (
AgentID INT(8) AUTO_INCREMENT,
FirstName VARCHAR(50) NOT NULL,
LastName VARCHAR(50) NOT NULL, 
PropertiesManaged VARCHAR (50) NOT NULL,
PhoneNumber VARCHAR (12),
CONSTRAINT PRIMARY KEY (AgentID),
CONSTRAINT PropertiesManaged FOREIGN KEY (PropertyID) REFERENCES Properties (PropertyID)
);

您必须定义列:

CREATE TABLE Agents (
AgentID INT(8) AUTO_INCREMENT,
FirstName VARCHAR(50) NOT NULL,
LastName VARCHAR(50) NOT NULL, 
PropertiesManaged VARCHAR (50) NOT NULL,
PhoneNumber VARCHAR (12),
PropertyId INT(8),
----^
CONSTRAINT PRIMARY KEY (AgentID),
CONSTRAINT PropertiesManaged FOREIGN KEY (PropertyID) REFERENCES Properties (PropertyID)    
);

相关内容

  • 没有找到相关文章

最新更新