Error: 150 "Foreign key constraint is incorrectly formed

1

I had an error in creating a FOREIGN KEY. I'd like to know what I'm doing wrong. Well, I've been trying for some time to find out what the error is. Thank you Annex code Sql:

CREATE DATABASE freatico;
USE freatico;
CREATE TABLE medicion (
    ID int(4) AUTO_INCREMENT PRIMARY KEY,
    IDP int(4) not null,
    Nivel float(5) not null, 
    Hora time not null, 
    Fecha date not null, 
    Persona text(40) not null,
    SMS varchar(70) not null,
    FOREIGN KEY(IDP) REFERENCES puntos(Id)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE puntos (
    Id int(4) PRIMARY KEY not null,
    Localizacion text(35) not null,
    UltiMed float(5) not null, 
    Vreferencia float(5) not null, 
    AlTubo float(5) not null, 
    SMS varchar(60) not null
)
ENGINE=InnoDB DEFAULT CHARSET=utf8; 

CREATE TABLE usuarios (
    ID int(4) AUTO_INCREMENT PRIMARY KEY, 
    Nombre text(40) not null, 
    Correo varchar(50)not null,
    Username varchar(20) not null, 
    Password varchar(40) not null,
    Cargo text(50) not null
)
ENGINE=InnoDB DEFAULT CHARSET=utf8;
    
asked by Ângel Dâvíd Bermëo 18.05.2018 в 22:20
source

1 answer

0

The problem is that you are trying to reference a table that does not exist. The solution is to create the table puntos first and then the table medicion

    
answered by 18.05.2018 / 22:24
source