0

When I try to run SQLMetal on a sqlite database which defines a foreign key constraint on multiple fields, i get an error.

The table is as follows:

CREATE TABLE A (
    a1 INTEGER,
    a2 INTEGER,
    PRIMARY KEY (a1,a2)
);
CREATE TABLE B (
    b1 INTEGER,
    b2 INTEGER,
    b3 INTEGER,
    b4 TEXT,
    PRIMARY KEY (b1,b2,b3),
    FOREIGN KEY (b1,b2) REFERENCES A (a1,a2)
);

The error message is:

"sqlmetal: Sequence contains more than one matching element"

Anybody knows how to resolve that problem?

M.S.
  • 442
  • 3
  • 13

1 Answers1

0

I think the issue is that you can only have one primary key per table. Here's the blurb from the sqlite documentation:

"Each table in SQLite may have at most one PRIMARY KEY. If the keywords PRIMARY KEY are added to a column definition, then the primary key for the table consists of that single column. Or, if a PRIMARY KEY clause is specified as a table-constraint, then the primary key of the table consists of the list of columns specified as part of the PRIMARY KEY clause. If there is more than one PRIMARY KEY clause in a single CREATE TABLE statement, it is an error."

  • "[..] Or, if a PRIMARY KEY clause is specified as a table-constraint, then the primary key of the table consists of the **list of columns** specified as part of the PRIMARY KEY clause [..]" As you already cited, it is allowed to define a primary key as a list of columns, so thats not the issue – M.S. Sep 17 '13 at 12:08
  • See http://www.sqlite.org/foreignkeys.html - Section 3 - Example "child3" and "child8". My Tables are fine, and its not sqlite3 which gives me trouble but SQLMetal – M.S. Sep 17 '13 at 12:13