我一直在我的psql数据库中收到此错误;
bikefacility=# ERROR: syntax error at or near "c"
bikefacility-# LINE 1: c
bikefacility-# ^
bikefacility-# bikefacility=# ALTER TABLE bicycle ADD CONSTRAINT fk_maintenance_contact_person FOREIGN KEY (maintenance_contact_person) REFERENCES maintenance(maintenance_contact_person);
ERROR: syntax error at or near "ERROR"
LINE 1: ERROR: syntax error at or near "c"
^
bikefacility=# ERROR: column "maintenance_contact_person" referenced in foreign key constraint does not exist
bikefacility-# bikefacility=# ALTER TABLE bicycle ADD CONSTRAINT fk_rental_period FOREIGN KEY (rental_period) REFERENCES rental(rental_period);
ERROR: syntax error at or near "ERROR"
LINE 1: ERROR: column "maintenance_contact_person" referenced in fo...
^
bikefacility=# ERROR: column "rental_period" referenced in foreign key constraint does not exist
bikefacility-# bikefacility=# ALTER TABLE bicycle ADD CONSTRAINT fk_terminal_id FOREIGN KEY (terminal_id) REFERENCES terminal(terminal_id);
ERROR: syntax error at or near "ERROR"
LINE 1: ERROR: column "rental_period" referenced in foreign key con...
^
bikefacility=# ERROR: column "terminal_id" referenced in foreign key constraint does not exist
这是我的代码。我在代码中创建了相同样式的外键,如您在此处看到的。
CREATE TABLE member (
member_id INTEGER PRIMARY KEY,
member_fname VARCHAR(15) NOT NULL,
member_lname VARCHAR(15) NOT NULL,
member_status VARCHAR(15) NOT NULL,
member_address VARCHAR(10) NOT NULL,
member_email VARCHAR(30) NOT NULL
);
CREATE TABLE bicycle (
bicycle_id INTEGER PRIMARY KEY,
bicycle_brand VARCHAR(25) NOT NULL,
bicycle_model VARCHAR(25) NOT NULL,
bicycle_colour VARCHAR(15) NOT NULL,
bicycle_type VARCHAR(20) NOT NULL,
bicycle_size VARCHAR(10) NOT NULL,
bicycle_availability VARCHAR(20) NOT NULL
);
ALTER TABLE bicycle ADD CONSTRAINT fk_bicycle_pickup_date FOREIGN KEY (bicycle_pickup_date) REFERENCES rental(bicycle_pickup_date) >MATCH FULL;
ALTER TABLE bicycle ADD CONSTRAINT fk_maintenance_contact_person FOREIGN KEY (maintenance_contact_person) REFERENCES maintenance(maintenance_contact_person);
ALTER TABLE bicycle ADD CONSTRAINT fk_terminal_id FOREIGN KEY (terminal_id) REFERENCES terminal(terminal_id);
ALTER TABLE bicycle ADD CONSTRAINT fk_rental_period FOREIGN KEY (rental_period) REFERENCES rental(rental_period);
CREATE TABLE sponsor (
sponsor_id INTEGER PRIMARY KEY,
sponsor_name VARCHAR(15) NOT NULL,
sponsor_contact VARCHAR(30) NOT NULL,
sponsor_period DATE NOT NULL,
sponsor_address VARCHAR(50) NOT NULL,
sponsor_fee DECIMAL (6, 2) NOT NULL
);
CREATE TABLE terminal (
terminal_id INTEGER PRIMARY KEY,
terminal_address VARCHAR(50) NOT NULL,
terminal_minstorage VARCHAR(50) NOT NULL,
terminal_maxstorage VARCHAR(50) NOT NULL
);
CREATE TABLE rental (
rental_no INTEGER PRIMARY KEY,
rental_period DATE NOT NULL,
bicycle_pickup_date DATE NOT NULL
);
它说这些列不存在,但我知道它们存在,因为它们就在那儿!有人可以帮我吗?提前致谢!
最好的问候,Bjarni
没有表maintenance
,但您尝试对其进行引用。
rental
之类的外部表。bicycle_pickup_date
中没有字段maintenance_contact_person
,terminal_id
,rental_period
或bicycle.