De este código cogido en w3school, en mysql no me lanza la segunda tabla me dice
1005 - No puedo crear tabla
pruebas
.orders
(Error: 150 "Foreign key constraint is incorrectly formed") (Detalles…)
$servername="localhost";
$username="root";
$password="";
$dbname="pruebas";
//conección
$conn= new mysqli($servername,$username,$password,$dbname);
if($conn->connect_error){
die($conn->connect_error);
}
//creación de la tabla
$sql=" CREATE TABLE Persons (
ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
PRIMARY KEY (ID)
)";
if($conn->query($sql)===TRUE){
echo "table created";
}else{
echo "table failed or created";
}
$sql=" CREATE TABLE Orders (
OrderID int NOT NULL,
OrderNumber int NOT NULL,
PersonID int,
PRIMARY KEY (OrderID),
FOREIGN KEY (PersonID) REFERENCES Persons(PersonID)
)";
if($conn->query($sql)===TRUE){
echo "table created";
}else{
echo "table failed or created";
}