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
Can't primaryKey be String type? #313
Comments
🤷♀️ |
Has the problem been solved already? |
Not yet, I solved this by manually modifying the |
@Henvealf I have a string as a primary key too and everything works just fine. |
Where did you get this version from? Afaict there is only a 0.12.0. But I'll take a look and report back. |
@mqus my bad, it is 0.12.0. |
I just adjusted the integration tests ( onCreate: (database, version) async {
await database.execute(
'CREATE TABLE IF NOT EXISTS `person` (`id` INTEGER, `custom_name` TEXT NOT NULL, PRIMARY KEY (`id`))');
await database.execute(
'CREATE TABLE IF NOT EXISTS `dog` (`id` TEXT, `name` TEXT, `nick_name` TEXT, `owner_id` INTEGER, FOREIGN KEY (`owner_id`) REFERENCES `person` (`id`) ON UPDATE NO ACTION ON DELETE CASCADE, PRIMARY KEY (`id`))');
await database.execute(
'CREATE INDEX `index_person_custom_name` ON `person` (`custom_name`)');
await callback?.onCreate?.call(database, version);
}, in static final _dogMapper = (Map<String, dynamic> row) => Dog(
row['id'] as String,
row['name'] as String,
row['nick_name'] as String,
row['owner_id'] as int); And the tests ran through successfully after also changing the calls to the constructor in the tests. I'll assume that you already tried to remove the generated file and regenerate it from scratch, so can you share a bit more of your code, maybe a reproducable example? |
after
You can see the |
Thank you very much! I could reproduce it now. Group(
this.name, {
String id,
this.content = '',
String createTime,
String updateTime,
bool avail = true
}) : this.id = id ?? Uuid().v4(),
super(updateTime, avail); (note the additional Btw, the analyzer also complained about a missing parameter type of
I hope I could help 😉 |
Ah right, We should probably generate an error there if the type does not get matched. But this code is currently subject to change anyway due to #318 . What do you think, @vitusortner ? |
Such cases won't be possible anymore with the type converters implementation because we'll be making sure that used values and types are database-compatible. If they're not database-compatible out of the box, we'll be looking for matching type converters. If no converter can be found, an error will be thrown. |
This case was a special case where no type was set for a variable, so we should definitely look out for it (or test for it). But in either case this is an easy fix, if it occurs again. I will be closing this issue, as @Henvealf hasn't mentioned any other issues. If you still have this problem please reopen this issue or open a new one. |
When I create a entity like this:
After
flutter packages pub run build_runner build
, the dao mapper of generated in*.g.dart
file is :I need to change it manually every build as:
Otherwise it won't work when operate db :
Is this a bug?
Version:
The text was updated successfully, but these errors were encountered: