Problem with foreign keys in hosting with php

2

Hi, I would like you to help me, someone knows why:

create a database with powerdesigner for Mysql.

When I upload it locally, phpmyadmin with xammp works, all the foreign keys are created.

But when I upload it to phpmyadmin of a hostgator hosting, foreign keys are not created.

What do you think it could be?

create this test

/ ============================================ =================== / / * DBMS name: MySQL 5.0 / / Created on: 07/03/2018 14:18:26 / / ============================================================== ================= * /

drop table if exists LIBRARY;

drop table if exists BOOKS;

/ ============================================ =================== / / * Table: LIBRARY / / ============================================================== ================= * / create table LIBRARY (    BIB_CODIGO int not null,    BIB_NAME varchar (30),    primary key (BIB_CODIGO) );

/ ============================================ =================== / / * Table: BOOKS / / ============================================================== ================= * / create table BOOKS (    LIB_CODIGO int not null,    BIB_CODIGO int,    LIB_NAME varchar (30),    LIB_PAGINAS int,    primary key (LIB_CODIGO),    FOREIGN KEY (BIB_CODIGO) REFERENCES LIBRARY (BIB_CODIGO) ); when the local charge is created the FK but in the hosting that is hostgator they are not created and it does not indicate any error or anything

    
asked by Christian Esk 07.03.2018 в 19:11
source

1 answer

3

In many hosting the default engine when creating tables in MySQL is MyISAM , which does not support foreign keys.

You can see all the detail here :

|Funcionalidad                          |Soportado  |
|---------------------------------------|-----------|
|Soporta llaves foráneas (Foreign key)  |   No      |

However, it is possible to indicate in CREATE TABLE the engine you want for your tables. When not explicitly indicated, the table is created with the default engine that the database manager has.

For example, you can do this:

  -- TABLA BIBLIOTECA
    CREATE TABLE BIBLIOTECA 
    ( 
        BIB_CODIGO int not null, 
        BIB_NOMBRE varchar(30), primary key (BIB_CODIGO) 
    ) ENGINE=InnoDB;        

  -- TABLA LIBROS

    CREATE TABLE LIBROS 
    ( 
        LIB_CODIGO int not null, 
        BIB_CODIGO int , 
        LIB_NOMBRE varchar(30), 
        LIB_PAGINAS int, 
        primary key (LIB_CODIGO), 
        FOREIGN KEY (BIB_CODIGO) REFERENCES BIBLIOTECA(BIB_CODIGO) 
    )  ENGINE=InnoDB;
    
answered by 09.03.2018 / 02:05
source