mysql - Properly creating a relational database -


i have database 3 tables. table authentication contains following:

+----------+-----------------+------+-----+---------+----------------+ | field    | type            | null | key | default |          | +----------+-----------------+------+-----+---------+----------------+ | id       | int(6) unsigned | no   | pri | null    | auto_increment | | userid   | varchar(30)     | no   |     | null    |                | | password | varchar(30)     | no   |     | null    |                | | role     | varchar(20)     | no   |     | null    |                | | email    | varchar(50)     | yes  |     | null    |                | +----------+-----------------+------+-----+---------+----------------+ 

login contains following:

+--------------+-----------------+------+-----+---------+----------------+ | field        | type            | null | key | default |          | +--------------+-----------------+------+-----+---------+----------------+ | id           | int(6) unsigned | no   | pri | null    | auto_increment | | timeloggedin | text            | no   |     | null    |                | | sessionid    | varchar(255)    | no   |     | null    |                | +--------------+-----------------+------+-----+---------+----------------+ 

and activity:

+----------+-----------------+------+-----+---------+-------+ | field    | type            | null | key | default | | +----------+-----------------+------+-----+---------+-------+ | id       | int(6) unsigned | no   | pri | null    |       | | torrents | mediumtext      | no   |     | null    |       | +----------+-----------------+------+-----+---------+-------+ 

there relation between id fields of authentication id in other tables.

i need add multiple rows in activity, several values torrents each id. unfortunately, when try adding new row duplicated id value with:

insert `activity` (`id`, `torrents`) values ('1', 'dssfsdffdsffs'); 

it gives me error: #1062 - duplicate entry '1' key 'primary'

how solve it? how did create table wrong?

i've read following apparently duplicate questions:

  1. #1062 - duplicate entry key 'primary'

but though says remove primary key, mysql didnt allow me create relationship unless made primary key.

you cannot initiate one-to-many relation referring primary key primary key. that'll one-to-one relationship.

in both login , activity tables need have foreign key refer authentication's id. example:

 constraint `fk_login` foreign key (`authenticationid`) references `authentication` (`id`) on delete cascade on update cascade 

Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -