MySQL error 150 problem - foreign key
Posted: Tue Jun 16, 2009 9:52 am
Hi all,
I am reading the book php5 pro and I have stacked on one chapter because of error 150.
I have build the database managercontact and the new table which looks like this :
Now after creating this table I am doing another query which looks like this :
The problem is that when I am lunching second script I get this error :
to second script the error still apears.
During reserching the problem I was also trying to do the second table first with SET FOREIGN_KEY_CHECKS=0 and than first script. In this case the second table query is correct but then after lunching first script the error aperas.I was also trying to add the line FOREIGN_KEY_CHECKS to first script but with no results.
Any ideas how to fix it ?
I am reading the book php5 pro and I have stacked on one chapter because of error 150.
I have build the database managercontact and the new table which looks like this :
Code: Select all
<?php
require('conn.php');
$sql = "CREATE TABLE jednostka (
jednostka_id SERIAL PRIMARY KEY NOT NULL,
snazwa1 varchar(100) NOT NULL,
snazwa2 varchar(100) NOT NULL,
ctyp char(1) NOT NULL
)";
$query = mysql_query($sql) or die(mysql_error());
echo 'table created!';
?>
Code: Select all
<?php
require('conn.php');
$sql = "CREATE TABLE adres (
adres_id SERIAL PRIMARY KEY NOT NULL,
jednostka_id int,
sadres1 varchar(255),
sadres2 varchar(255),
smiasto varchar(255),
skod varchar(10),
styp varchar(50),
CONSTRAINT fk_adres_jednostka_id
FOREIGN KEY (jednostka_id) REFERENCES jednostka(jednostka_id)
)";
$query = mysql_query($sql) or die(mysql_error());
?>
Even after I am adding this line of codeCan't create table 'contactmanager.adres' (errno: 150)
Code: Select all
$query = mysql_query('SET FOREIGN_KEY_CHECKS=0') or die(mysql_error())
During reserching the problem I was also trying to do the second table first with SET FOREIGN_KEY_CHECKS=0 and than first script. In this case the second table query is correct but then after lunching first script the error aperas.I was also trying to add the line FOREIGN_KEY_CHECKS to first script but with no results.
Any ideas how to fix it ?