1
我相信這個問題已經被問了很多次了。 如果有人可以看看它會很棒似乎無法調試MySQL錯誤「#1064
我得到#1064 - 你的SQL語法有錯誤;檢查與您的MySQL服務器版本相對應的手冊,在正確的語法中使用 'REFERENCES interests(interests_id)'''),同時使用interests.interest_id創建category_interests和event_attendees表作爲定義外鍵的參考。
我似乎無法找到它的原因。
SET foreign_key_checks = 0;
DROP table IF EXISTS categories;
CREATE table categories(
category_id int AUTO_INCREMENT,
category_name VARCHAR(40),
category_desc TEXT,
CONSTRAINT pk_categories PRIMARY KEY (category_id)
);
DROP table IF EXISTS interests;
CREATE table interests(
interest_id int AUTO_INCREMENT,
interest_name varchar(40),
CONSTRAINT pk_interests PRIMARY KEY (interest_id)
);
-- ERROR - query does not run
DROP table IF EXISTS category_interests;
CREATE table category_interests(
interest_id int,
category_id int,
CONSTRAINT fk_interests FOREIGN KEY interest_id REFERENCES interests(interest_id),
CONSTRAINT fk_categories FOREIGN KEY category_id REFERENCES categories(category_id)
);
-- ERROR - query does not run
DROP table IF EXISTS event_atendees;
CREATE table event_atendees(
attendee_id int AUTO_INCREMENT,
interest_id int,
lat double,
lon double,
name varchar(115),
dob date,
gender CHAR(1),
CONSTRAINT pk_event_atendees PRIMARY KEY (attendee_id),
CONSTRAINT fk_intrests_ea FOREIGN KEY interests_id REFERENCES `interests`(interests_id)
);
SET foreign_key_checks = 1;
我已經提到我所做的更改。這是您的模式的工作演示。 http://sqlfiddle.com/#!9/d6c965/2/0。 @NishonTandukar – 1000111
我修復了已識別的錯誤 現在我得到了#1215 - 無法添加外鍵約束' 而我嘗試創建** event_atendess **表 –
它不是應該是'event_atendees'嗎?請檢查工作演示。它成功執行所有查詢。 – 1000111