php - Allow duplicate in table -


i'm relatively new databases, database architecture , mysql in general, forgive me if method isn't optimal. have created table called comments, want store users id in column post_id works fine stands. table's sole purpose store messages posted on given users profile , other related information.

however want allow duplicate entries can read comments table , users id, take column comments comments table , display them on users profile id matched.

i'd doing inner join on comments , user_info, post_id comments , id user_info.

when posting information database users profile, below error

sqlstate[23000]: integrity constraint violation: 1062 duplicate entry '59' key 'post_id'  

user_info

'user_info', 'create table `user_info` (\n  `id` int(11) not null auto_increment,\n  `username` varchar(12) collate utf8_unicode_ci not null,\n  `pass` varchar(40) collate utf8_unicode_ci default null,\n  `joined` timestamp not null default current_timestamp,\n  primary key (`id`),\n  unique key `username` (`username`)\n) engine=innodb auto_increment=64 default charset=utf8 collate=utf8_unicode_ci' 

comments

'comments', 'create table `comments` (\n  `post_id` int(11) default null,\n  `comment` text collate utf8_unicode_ci,\n  `date_posted` timestamp not null default current_timestamp,\n  unique key `post_id` (`post_id`)\n) engine=innodb default charset=utf8 collate=utf8_unicode_ci' 

let me know if i'm missing potentially answer question.

you need drop unique index on post_id:

alter table `comments` drop index post_id; 

then can create non-unique index if necessary:

alter table `comments` add index `post_id` (`post_id`); 

also comments table lacks primary key. create auto increment integer column: comment_id, identify record.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -