 ALTER TABLE Messages ADD CONSTRAINT Messages_Group_Id FOREIGN KEY (groupId)
     REFERENCES Groups (id) ON UPDATE CASCADE ON DELETE CASCADE;
     
+ALTER TABLE Messages ADD CONSTRAINT Messages_Location FOREIGN KEY (location)
+    REFERENCES Locations (position) ON UPDATE CASCADE ON DELETE CASCADE;
     
 -- Localisations
 ALTER TABLE Localisations ADD CONSTRAINT Localisations_Account_Id FOREIGN KEY (accountId)

    groupId int NOT NULL,
    accountId int NOT NULL,
    date timestamp NOT NULL,
    status int NOT NULL DEFAULT 1,                   /* Number of read */
    importance decimal(1) NOT NULL DEFAULT 0,        /* 0: Normal, 1: Important, 2: Very Important */
    content varchar(500) NOT NULL,
    CONSTRAINT Messages_pk PRIMARY KEY (id)
);

CREATE TABLE Localisations (
    id int NOT NULL AUTO_INCREMENT,
    position varchar(25) NOT NULL,
    accountId int NULL,
    eventId int NULL,
    date timestamp NOT NULL,
    CONSTRAINT Localisations_pk PRIMARY KEY (id)
);

CREATE TABLE Events (
    id int NOT NULL AUTO_INCREMENT,
    localisation varchar(25) NOT NULL,
    date timestamp NOT NULL,
    nbParticipants int NOT NULL DEFAULT 0,
    nbParticipantsMax int NOT NULL,
    length int NOT NULL,
    CONSTRAINT Events_pk PRIMARY KEY (id)
);


    
ALTER TABLE Localisations ADD CONSTRAINT Localisations_Event_Id FOREIGN KEY (eventId)
    REFERENCES Events (id) ON UPDATE CASCADE ON DELETE CASCADE;
    
ALTER TABLE Localisations ADD CONSTRAINT Localisations_Location FOREIGN KEY (location)
    REFERENCES Locations (position) ON UPDATE CASCADE ON DELETE CASCADE;
    
-- Events
ALTER TABLE EventParticipants ADD INDEX EventParticipants_Accounts_Events (accountId, eventId);
