Skip to content

Composite primary keys are not being supported #2

@tylertreat

Description

@tylertreat

What steps will reproduce the problem?

  1. Create a model with multiple primary key annotations.
  2. Let Infinitum try to create a table from this model.

What is the expected output? What do you see instead?
Currently, the framework does not allow for multiple primary keys. A ModelConfigurationException will be thrown at runtime if a model has two or more primary keys designated.

Composite keys are supported in SQLite using the PRIMARY KEY(foo, bar, ...) syntax, but there was an issue in getting composite key columns to autoincrement.

This should be addressed in a future version. Labeling priority as low as there is a slight workaround for the issue described below:

Although a true composite key is currently not possible, a compound key can be achieved by designating the "primary key" columns as unique, i.e. UNIQUE(foo, bar, ...). These columns can then be marked to autoincrement in their declarations. For example...

create table foobar(id INTEGER PRIMARY KEY, foo INTEGER AUTOINCREMENT NOT NULL, bar TEXT NOT NULL, baz TEXT, UNIQUE(foo, bar));

This creates a pseudo-compound key as id is marked as a primary key which will implicitly increment automatically, and foo and bar are marked as unique with foo incrementing automatically.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions