Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2004
    Posts
    3

    Unanswered: Problem with foreign keys in DerbyDB

    Hi

    I have 2 tables:

    CREATE TABLE users (
    id_user INTEGER NOT NULL GENERATED
    ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
    name VARCHAR(30),
    PRIMARY KEY (id_user)
    );

    CREATE TABLE articles (
    id_article INTEGER NOT NULL GENERATED
    ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
    creator SMALLINT NOT NULL,
    PRIMARY KEY (id_article)
    FOREIGN KEY (creator) REFERENCES users (id_user)
    );

    Second table doesn`t create.
    Error message is:

    ERROR X0Y44: Constraint 'SQL061110025111171' is invalid: there is no unique or primary key constraint on table 'APP.UZIVATELE' that matches the number and types of the columns in the foreign key.

    Where is the problem?

  2. #2
    Join Date
    Aug 2004
    Posts
    3

    Solution

    The reason is:
    id_user is INTEGER
    creator is SMALLINT
    and INTEGER nad SMALLINT are non-full-compatible types.

    If creator is INTEGER, all is OK.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •