Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to tell which attribute is the primary key? #1

Closed
MohiuddinM opened this issue Mar 11, 2019 · 4 comments
Closed

How to tell which attribute is the primary key? #1

MohiuddinM opened this issue Mar 11, 2019 · 4 comments

Comments

@MohiuddinM
Copy link

No description provided.

@simolus3
Copy link
Owner

Hi,
there are two ways to specify the primary key:

  1. When you have just one column in the primary key that also uses auto-increment: Just call the autoIncrement() method on the column getter, like this: https://github.com/simolus3/moor/blob/8fe350219c1040ff88218c12dce977cb28edf7e7/moor_flutter/example/lib/database/database.dart#L9
  2. For custom primary keys: Override the primaryKey getter to return a set of fields. An example is here: https://github.com/simolus3/moor/blob/8fe350219c1040ff88218c12dce977cb28edf7e7/moor/test/data/tables/todos.dart#L31-L35

Is this what you need?

@MohiuddinM
Copy link
Author

Thank you for your quick answer!
I am now using the second method, and it gives the following error:
'Xxx.primaryKey' ('() → Set') isn't a valid override of 'Table.primaryKey' ('() → Set<Column<dynamic, SqlType>>').

@simolus3
Copy link
Owner

Hm, that would indicate that the type of the overriden getter is wrong. Did you explicitly add the type annotation Set<Column> instead of just Set?
If it's not a problem, pasting your table class could also help me see what's going on (feel free to obscure the class / getter names).

@MohiuddinM
Copy link
Author

The problem is resolved! It wanted me to import the moor.dart

simolus3 pushed a commit that referenced this issue May 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants