@Orm(tableName: 'database_table', generateMigrations: false)
@serializable
abstract class _MyModel {
@primaryKey
@SerializableField(alias: 'RowId', isNullable: false)
int get rowId;
@Column(type: ColumnType.text)
String? nameEn;
}
Then I run dart run build_runner build to generate the model.g.dart file. This works.
But an error occurs when I try to run my program which looks like this:
Future<List<MyModel >> getTableData() async {
var settings = ConnectionSettings(
host: 'localhost',
port: 3306,
db: database,
user: user,
password: password);
var connection = await MySqlConnection.connect(settings);
var executor = MariaDbExecutor(connection);
// Get all fields of the table.
var query = MyModelQuery();
var result = await query.get(executor);
await connection.close();
return result;
}
The exception message:
Exception has occurred.
_TypeError (type 'Blob' is not a subtype of type 'String?' in type cast)
The exception occurs in the model.g.dart file in the "parseRow" function.
Optional<MyModel > parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = MyModel (
nameEn: fields.contains('name_en') ? (row[0] as String?) : null, //<--- THE EXCEPTION THROWS HERE.
rowId: fields.contains('RowId') ? (row[1] as int) : 0,
);
return Optional.of(model);
}
Everything works fine if I replace the problematic line with:
If the field in the database is a VarChar and not a Text, everything runs correctly.
So I think it's the "@Column(type: ColumnType.text)" which doesn't work as it supposed.
I had to create a class and override the "parseRow" function to make it work.
Would be great if this issue could be fixed. Thank you.
I have this orm model:
Then I run
dart run build_runner build
to generate the model.g.dart file. This works.But an error occurs when I try to run my program which looks like this:
The exception message:
The exception occurs in the model.g.dart file in the "parseRow" function.
Everything works fine if I replace the problematic line with:
If the field in the database is a VarChar and not a Text, everything runs correctly. So I think it's the "@Column(type: ColumnType.text)" which doesn't work as it supposed.
I had to create a class and override the "parseRow" function to make it work. Would be great if this issue could be fixed. Thank you.