Skip to content

Can I use a nullable column in the primary key? #2899

Answered by simolus3
cian-bayer asked this question in Q&A
Discussion options

You must be logged in to vote

we were going back and forth between having a default -1 value or something, but I think keeping it null is important here.

It's a bit counter-intuitive, but you could apply a type converter mapping from nullable values in Dart to a non-null value in SQL. But then it's important to remember that SQL features like IS NULL will no longer work.

How would I resolve primaryKey constraint failures during a migration?? In this case I wouldn't care which of the duplicates were kept.

The best way to drop duplicates (that I can think of) is to use a custom query with common table expressions. I think this query would drop duplicates across column1, column2 and column4, for instance:

WITH
  firs…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

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

Answer selected by cian-bayer
@cian-bayer
Comment options

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