0
I have a users table and a friendship table, a friend is also a user and when I add a user as a friend he also has to be my friend, now that the concept is clear, I would like to know how to create this table because the following error is occurring:
CREATE TABLE IF NOT EXISTS postagens(
id INT NOT NULL AUTO_INCREMENT,
u_id INT,
titulo VARCHAR(128) NOT NULL,
conteudo VARCHAR(4096),
imagem VARCHAR(256),
audio VARCHAR(256),
video VARCHAR(256),
CONSTRAINT id_pk PRIMARY KEY(id),
CONSTRAINT u_id_fk FOREIGN KEY(u_id) REFERENCES usuarios(id)
) DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS amizade(
id INT NOT NULL AUTO_INCREMENT,
u_id INT,
a_id INT,
CONSTRAINT id_pk PRIMARY KEY(id),
CONSTRAINT u_id_fk FOREIGN KEY(u_id) REFERENCES usuarios(id),
CONSTRAINT a_id_fk FOREIGN KEY(a_id) REFERENCES usuarios(id)
) DEFAULT CHARSET=utf8;
Is mysql or mariadb ?
– rbz
Sorry, the concept is still not very clear. I could explain better: a friend is also a user and when I add a user as a friend he also has to be my friend. Additionally, you can ask the question the table structure
usuarios
?– Andrey
i have no way to test mysql here, only with Sql server... if I run it on S.Server it gives error if I do not create the key Primary in the users table. In your time?
– aa_sp
Sorry Mother, I don’t understand!
– Danrley Fernandes Lopes
RBZ is mariadb, but there is some difference?
– Danrley Fernandes Lopes
What else is in this db? I tested the query here and it worked perfectly, you must be duplicating something as it says in the error, there must already be some other table using the keys
– Woton Sampaio
I believe the friendship table already exists and you instead of creating it, you want to add/change some field
– Woton Sampaio
I meant if Voce created PRIMARY KEY in the use table Users
– aa_sp
@Danrleyfernandeslopes, the tags are to determine exactly your scenario. If you put tags that are unrelated, yes, they may have differences depending on the context.
– rbz
Some differences for new functions: https://mariadb.com/kb/en/library/mariadb-vs-mysql-features/
– rbz