Skip to content

Database create(table:) - Why should multiple columns in primary key be consecutive? #1326

Answered by groue
changyjacky asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @changyjacky,

Your alternative solution is to add an explicit PRIMARY KEY constraint:

try db.create(table: "team_member") { t in
    t.column("playerid", .integer).notNull()
    t.column("note", .text)
    t.column("teamid", .integer).notNull()
    t.primaryKey(["playerId", "teamId"])
}

Take care, though, to add a NOT NULL constraint to each primary key column.

I'll update the documentation so that it is clearer.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@groue
Comment options

@changyjacky
Comment options

Answer selected by changyjacky
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants