Key Foreign Relationship Problem in Phpmyadmin - Wamp

Asked

Viewed 1,778 times

2

I have 'problem' in my Wamp, more precisely in the latest version (Wampserver 3.0.6 64 bit x64).

When I create 2 tables, example:

CREATE TABLE categoria(
    id_categoria INT NOT NULL AUTO_INCREMENT,
    nome VARCHAR(100) NOT NULL,
    PRIMARY KEY(id_categoria)
);


CREATE TABLE chamado(
    id_chamado INT NOT NULL AUTO_INCREMENT,
    id_categoria INT NOT NULL,
    titulo VARCHAR(45) NOT NULL,
    PRIMARY KEY(id_chamado),
    FOREIGN KEY(id_categoria) REFERENCES categoria(id_categoria)
);

Running and creating the tables, however, Phpmyadmin does not automatically create the relationship between the foreign key and the primary key of the other table, things that with XAMP work automatically.

I need to automatically create the relationship between the tables, even so I can use Mysql with Hibernete (happens with Hibernete also).

I think it might be some configuration, someone would know how to solve?

Thanks in advance.

-----------> Updating:

Table Category: inserir a descrição da imagem aqui

Table Called: inserir a descrição da imagem aqui

Insert into table Called through Phpmyadmin:

inserir a descrição da imagem aqui

As much as the category table has records, I can add any id in the foreign key of the called table that no error occurs. Things that, using Xamp, works, which relates the two tables and opens an option with the foreign key id at Insert time.

  • Check if the problem you are having is not Storage Engine

  • Even specifying foreign keys, I can do Inserts without referencing, deleting, and nothing returns error.

  • @Agnaldojunior, you tried to do like Dnick said, it would be something like ALTER TABLE nome_da_tabela ENGINE=INNODB, or in phpMyadmin in Operations > table options, and change the Storage Engine

  • I tried to do this, but it didn’t solve it. I updated the post by adding more details.

1 answer

1

A foreign key (FK) is a column or combination of columns used to establish and enforce a link between the data of two tables in order to control the data that can be stored in the foreign key table.  In a foreign key reference, a link is created between two tables when the column or columns containing the primary key value for a table are referenced by the column or columns of another table.  This column becomes a foreign key in the second table.

Therefore, it can be null, or have a value not referenced in the other table. It does not necessarily need to exist in the two tables.

From the photos the foreign key is working. Make a query using data from the two tables to test its functionality.

Testing:

Select ca.nome, ch.titulo from categoria as ca, chamado as ch where ch.id_categoria = ca.id_categoria

Browser other questions tagged

You are not signed in. Login or sign up in order to post.