Skip to content

Is it possible to create a foreign key to a composite primary key for SQLite? #2090

Open
@tom42

Description

@tom42

Describe the question

I'm trying to create a foreign key to a composite primary key for SQLite as shown below:

CREATE TABLE Area(
  ArticleId TEXT NOT NULL,
  AreaGroupIndex INTEGER NOT NULL,
  "Index" INTEGER NOT NULL,
  PRIMARY KEY(ArticleId, AreaGroupIndex, "Index"),
  FOREIGN KEY(ArticleId, AreaGroupIndex) REFERENCES AreaGroup(ArticleId, "Index") ON DELETE CASCADE
)

The issue is that SQLite allows foreign key creation only as part of a CREATE TABLE statement as shown above, and I cannot figure out how to do this with FluentMigrator's fluent syntax or whether it is possible at all (I searched the issues here and the answer seems to be 'no'?)

Expected benefit
I can of course create my tables with Execute.Sql, but I'd really prefer if it was possible with fluent syntax. We make use of fluent syntax to basically reuse fragments of SQL code, and we lose that ability whenever we write raw SQL.

Information (please complete the following information):

  • FluentMigrator 7.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions