Flutter moor: Got error when adding moor file to make index


I am trying to use flutter moor on my application. So after creating a column:

import 'package:moor_flutter/moor_flutter.dart';

class LocationTables extends Table {
  TextColumn get locationUuid => text()();
  RealColumn get latitude => real()();

Now I want to make locationUuid as index. So According it’s official site I created a moor file to add index:

CREATE INDEX location_uuid_index ON LocationTables (locationUuid);

after that I added this file in db calss:

@UseMoor(include: {
}, tables: [
], daos: [

class Database extends _$Database {

But after run build runner:

pub run build_runner build --delete-conflicting-outputs

I got This error:

[WARNING] moor_generator:moor_generator on lib/database/database.dart:
line 3, column 37: Target table LocationTables could not be found.
3 │ CREATE INDEX location_uuid_index ON LocationTables (locationUuid);


I find a solution. I put answer to help someone:

In moor file I have to write table name like this:

CREATE INDEX location_uuid_index ON location_tables (location_uuid);

and after that build runner was success.

And This added in database.g.dart:

abstract class _$Database extends GeneratedDatabase {
  _$Database(QueryExecutor e) : super(SqlTypeSystem.defaultInstance, e);
  $LocationTablesTable _locationTables;
  $LocationTablesTable get locationTables =>
      _locationTables ??= $LocationTablesTable(this);
  Index _locationUuidIndex;
  Index get locationUuidIndex => _locationUuidIndex ??= Index(
      'CREATE INDEX location_uuid_index ON location_tables (locationUuid);');

Attention to :

  • location_tables

  • location_uuid

Answered By – Cyrus the Great

Answer Checked By – Mary Flores (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *