2 votes

Problem with foreign keys in hosting with php

Hello I ayudensi someone knows the because:

create a database with powerdesigner to Mysql.

When I charge it in the local phpmyadmin with xammp it all works to create the key foreign.

But when I charge it in phpmyadmin on a hosting from hostgator are not created the key foreign.

Who believe that you can 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_NOMBRE varchar(30), primary key (BIB_CODIGO) );

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

4voto

A. Cedano Points 48884

In many hosting the engine by default 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 specify in the CREATE TABLE the engine that you want for your tables. When not explicitly stated, the table is created with the engine by default so that you have the database manager.

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;

HolaDevs.com

HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by:

X