Problem with foreign keys - Mailing list pgsql-general

From usenet@krap.dk (Svenne Krap)
Subject Problem with foreign keys
Date
Msg-id 3b769218.11375146@news.tele.dk
Whole thread Raw
List pgsql-general
Hi,

below is the sql-script and the error as an comment after the error,
nothing works :)

I find it strange, have checked for typos, any help ???

Svenne


### from here ###

create sequence customer_customerid_seq;

create table customer (
        customerid integer,
        companyname varchar,
        attention varchar,
        address1 varchar not null,
        address2 varchar,
        zip varchar not null,
        city varchar not null,
        country varchar,
        phone varchar not null,
        fax varchar,
        email varchar,
        website varchar,
        created timestamp with time zone default now() not null,
        active boolean default't'::bool not null,
        comment varchar,
        primary key (customerid)
);

create sequence componentid_seq;

create table component (
        componentid int4 not null,
        parttype varchar not null,
        brand varchar not null,
        partnumber varchar not null,
        description varchar,
        producturl varchar,
        supporturl varchar,
        driverurl varchar,
        primary key(componentid)
);

create sequence basetypeid_seq;

create table basetype(
        basetypeid int4 not null,
        name varchar not null,
        primary key (basetypeid)
);

create sequence familyid_seq;

create table family (
        familyid int4 not null,
        familyname varchar not null,
        basetypeid int4 not null references basetype(basetypeid),
        primary key(familyid)
);

create sequence machinetypeid_seq;

create table machinetype(
        machinetypeid int4 not null,
        familyid int4 not null references family(familyid),
        partname varchar not null,
        price float,
        deliverystatus varchar,
        primary key(machinetypeid, familyid)
);

create table rel_type_component (
        componentid int4 not null references component(componentid),
        machinetypeid int4 not null references
machinetype(machinetypeid),
        primary key (componentid, machinetypeid)
);

### ERROR: ERROR:  UNIQUE constraint matching given keys for
referenced table "machinetype" not found

create sequence machineid_seq;

create table machine(
        machineid int4 not null,
        customerid int4 not null references customer(customerid),
        machinetypeid int4 not null references
machinetype(machinetypeid),
        bought timestamp,
        primary key (machineid)
);

### ERROR: ERROR:  UNIQUE constraint matching given keys for
referenced table "machinetype" not found

create sequence serviceid_seq;

create table servicerecord(
        serviceid int4 not null,
        machineid int4 not null references machine(machineid),
        opened timestamp not null default now(),
        closed timestamp,
        description varchar not null,
        primary key(serviceid)
);

### this is understandable, as prior creation failed. :)
### ERROR:  Relation 'machine' does not exist


pgsql-general by date:

Previous
From: Jochem van Dieten
Date:
Subject: PostgresQL setup in hosted environment
Next
From: "omid omoomi"
Date:
Subject: Re: Problem with foreign keys