简体   繁体   中英

Flutter Drift - parameters prohibited in CHECK constraints

I'm trying to use the drift library (renamed from moor ) ,but it's unable to create tables because of this error:

SqliteException(1): parameters prohibited in CHECK constraints, SQL logic error (code 1)
  CREATE TABLE IF NOT EXISTS enterprise (name TEXT NOT NULL CHECK(LENGTH(name) <= ?), ..other fields);

This is the table class causing the error:

class Enterprise extends Table {

  TextColumn get name =>
      text().check(name.length.isSmallerOrEqualValue(maxNameLength))();

  // ...other fields
}

The error goes away if I remove the check . Could someone explain why the check isn't working ?

Turns out it's a bug with drift. This is the workaround as suggested by the author of drift, and will be fixed in a future release.

Replace

check(name.length.isSmallerOrEqualValue(maxNameLength))

With this:

check(name.length.isSmallerOrEqual(Constant(maxNameLength)))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM