无法在Flutter中创建sqlite表

时间:2019-07-06 17:34:20

标签: android ios sqlite flutter

我正在尝试在Flutter中创建sqlite表,下面是我的代码:

  Future<void> create() async {
    var path = join(await getDatabasesPath(), 'weather.db');
    db = await openDatabase(
      path,
      onCreate: (db, version) async {
        await db.execute(
          'CREATE TABLE IF NOT EXISTS set_location(location_id INTEGER PRIMARY KEY, name TEXT, country TEXT)'
        );
        await db.execute(
          'CREATE TABLE IF NOT EXISTS coord(coord_id INTEGER, lon TEXT, lat TEXT, FOREIGN KEY(coord_id) REFERENCES set_location(location_id)'
        );
      },
      version: 1,
    );
  }

我收到一个错误:

flutter ( 9631): Error: DatabaseException(incomplete input (code 1 SQLITE_ERROR): , while compiling: CREATE TABLE IF NOT EXISTS coord(coord_id INTEGER PRIMARY KEY, lon TEXT, lat TEXT, FOREIGN KEY(coord_id) REFERENCES set_location(location_id))

更新: 如果我删除FOREIGN KEY..

,上面的代码将正常工作

0 个答案:

没有答案