MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 7th, 2008, 09:11 PM
rjstark rjstark is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2008
Posts: 1 rjstark User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 25 sec
Reputation Power: 0
Create A User Message Table

I need to create a "user message" table which stores messages sent between users in the system. The table will store who the message is sent to (msgTo) and who the message was sent from (msgFrom). I also need to create a foreign key to hold integrity because the msgTo and msgFrom is a specific user in the "users" table.

I'm trying to use a foreign key twice... The msgTo and msgFrom fields will both be a user id found on the "idusers" field.

Here is my table layout:

Code:
CREATE  TABLE IF NOT EXISTS `v1_02`.`userMessages` (
  `iduserMessages` INT NOT NULL ,
  `msgTo` VARCHAR(45) NULL ,
  `msgFrom` VARCHAR(45) NULL ,
  `Topic` VARCHAR(45) NULL ,
  `Message` BLOB NULL ,
  `deleted` BOOLEAN NULL ,
  `dateSent` DATETIME NULL ,
  `dateRead` DATETIME NULL ,
  `dateDeleted` DATETIME NULL ,
  PRIMARY KEY (`iduserMessages`) ,
  INDEX fk_userMessages_users (`msgTo` ASC) ,
  INDEX fk_userMessages_users2 (`msgFrom` ASC) ,
  CONSTRAINT `fk_userMessages_users`
    FOREIGN KEY (`msgTo` )
    REFERENCES `v1_02`.`users` (`idusers` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_userMessages_users2`
    FOREIGN KEY (`msgFrom` )
    REFERENCES `v1_02`.`users` (`idusers` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


I'm getting an error and I think it's because mysql won't allow me to create a references For instance, if I delete the foreign keys, it works just fine... But I want to keep the keys.

What do most people do when they want to create a message table? Can someone show me their schema?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Create A User Message Table


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT