用户
表:
CREATE TABLE `users` (
`uid` int(11) NOT NULL AUTO_INCREMENT,
`unique_id` varchar(23) NOT NULL,
`full_name` varchar(100) DEFAULT NULL,
`name` varchar(50) NOT NULL,
`email` varchar(100) NOT NULL,
PRIMARY KEY (`uid`),
UNIQUE KEY `unique_id` (`unique_id`) USING BTREE,
UNIQUE KEY `email` (`email`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=41 DEFAULT CHARSET=utf8;
项目
表:
CREATE TABLE `items` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`item_photo` text,
`item_name` varchar(100) DEFAULT NULL,
`item_description` varchar(500) DEFAULT NULL,
`item_price` varchar(10) DEFAULT NULL,
`user_id` int(11) DEFAULT NULL,
`category_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `fk_user_id` (`user_id`) USING BTREE,
KEY `fk_category_id` (`category_id`) USING BTREE,
CONSTRAINT `items_ibfk_1` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`),
CONSTRAINT `items_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `users` (`uid`)
) ENGINE=InnoDB AUTO_INCREMENT=64 DEFAULT CHARSET=utf8;
我想做的是为我的项目创建一个私有(private)消息系统。在此之前,我已经实现了一个评论系统并且运行良好(拉出具有相同item_id
的comments
)。可以看到DDL并查询here 。但说到这里,我发现很难想到私信模型。
基本上,私有(private)消息只是在两个用户(卖家和投标人)之间竞标商品价格。其他注册用户看不到其他人出价。
这是我创建Bids
表的尝试:
CREATE TABLE `bids` (
`id` int(11) NOT NULL,
`bid` float DEFAULT NULL,
`message` varchar(255) DEFAULT NULL,
`from_uid` varchar(255) DEFAULT NULL,
`to_uid` varchar(255) DEFAULT NULL,
`to_iid` int(11) DEFAULT NULL,
`time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
我也尝试过将外键放入 bids
表中,但对我来说似乎已经太复杂了。因此出现错误 1215 - Cannot addforeign keyconstraint :(
如果有什么事情请告诉我。
<小时/>编辑:字符集为utf8。无法创建外键约束
最佳答案
消息
message_id
conversation_id
user_id
message
对话
conversation_id
item_id
user_id
出价
bid_id
item_id
user_id
amount
关于php - 数据库架构 - 基于 'item' 创建私有(private)消息传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20538971/