floor icon indicating copy to clipboard operation
floor copied to clipboard

SqfliteDatabaseException (DatabaseException(no such table: featurings (code 1 SQLITE_ERROR): , while compiling: select * from featurings) sql 'select * from featurings' args [])

Open lunaderossi opened this issue 2 years ago • 5 comments

I have a project with three tables, but this specific "featurings" table is causing me so much trouble. Removing it makes the rest of the application work fine.

Featuring entity:

import 'package:floor/floor.dart';

import 'movie.dart';
import 'superhero.dart';

@Entity(tableName: 'featurings', foreignKeys: [
  ForeignKey(
      childColumns: ['movie'], parentColumns: ['id_movie'], entity: Movie),
  ForeignKey(
      childColumns: ['superhero'],
      parentColumns: ['id_superhero'],
      entity: SuperHero),
])
class Featuring {
  @primaryKey
  @ColumnInfo(name: 'id_feature')
  final int id;

  final int movie, superhero;

  Featuring(this.id, this.movie, this.superhero);
}

Featuring DAO:

import 'package:floor/floor.dart';

import '../entity/featuring.dart';

@dao
abstract class FeaturingDao {
  @Query('select * from featurings')
  Future<List<Featuring>> findAllFeaturings();

  @Query('select * from featurings where movie = :movieID')
  Future<List<Featuring>> findAllFeaturingsByMovie(int movieID);

  @Query('select * from featurings where superhero = :superheroID')
  Future<List<Featuring>> findAllFeaturingsBySuperHero(int superheroID);

  @insert
  Future<void> insertFeaturing(Featuring feat);
}

Code that is triggering the error message:

Future<void> loadSample(FeaturingDao featuringDao, MovieDao movieDao,
    SuperHeroDao superHeroDao) async {
  var data = await loadJsonData();

  if ((await featuringDao.findAllFeaturings()).isEmpty) { // Here it throws, but commenting the rest of the code makes it go smoothly
    for (int i = 0; i < data['featuring'].length; i++) {
      Featuring feat = Featuring(
          int.parse(data['featuring'][i]['id_feature']),
          int.parse(data['featuring'][i]['movie']),
          int.parse(data['featuring'][i]['superhero']));

      await featuringDao.insertFeaturing(feat);
    }
  }

  // Omitted the code that does the exact same thing for the other two tables
}

And in the autogenerated database file, the CREATE TABLE IF NOT EXISTS `featurings` (`id_feature` INTEGER NOT NULL, `movie` INTEGER NOT NULL, `superhero` INTEGER NOT NULL, FOREIGN KEY (`movie`) REFERENCES `movies` (`id_movie`) ON UPDATE NO ACTION ON DELETE NO ACTION, FOREIGN KEY (`superhero`) REFERENCES `superheroes` (`id_superhero`) ON UPDATE NO ACTION ON DELETE NO ACTION, PRIMARY KEY (`id_feature`)) query is present.

What am I doing wrong?

lunaderossi avatar Mar 10 '22 12:03 lunaderossi

Facing the same issue, while adding an entity to a new table.

Palwandew avatar May 25 '22 18:05 Palwandew

Facing this in both dev and release mode

lpylpyleo avatar Sep 18 '22 03:09 lpylpyleo

Please check the following: Was the table already there when it was generated the first time? Has it been added to the list of entities?

SEGVeenstra avatar Jul 04 '23 14:07 SEGVeenstra

I'm facing the same issue. it is in list of entities. What do you mean by "Was the table already there when it was generated the first time?"

dmgcoding avatar Dec 11 '23 10:12 dmgcoding

@dmgcoding sry, been a while, I don't even know what I meant by it myself. 😓

If you could share some code, or even better, make an isolated reproduction of the issue I'd be happy to take a look. But I must warn you, I don't have much in dept experience.

SEGVeenstra avatar Dec 11 '23 11:12 SEGVeenstra