首页 > 解决方案 > SQLiteLog( 8646): (1) table tempsettings has no column named user

问题描述

I'm learning how to upgrade databases in an flutter application, apears to be very simple, but I'm getting this error executing an INSERT:

E/SQLiteLog( 9107): (1) table tempsettings has no column named user I/flutter ( 9107): DatabaseException(table tempsettings has no column named user (code 1 SQLITE_ERROR): , while compiling: INSERT INTO tempsettings('id', 'user', 'company', 'url') SELECT 'id', 'user', 'company', 'url' FROM settings) E/SQLiteLog( 9107): (1) no such column: user I/flutter ( 9107): DatabaseException(no such column: user (code 1 SQLITE_ERROR): , while compiling: INSERT INTO settings('id', 'user', 'company', 'url', 'theme') SELECT id, user, company, url, 1 FROM tempsettings)

    await db
        .execute("CREATE TABLE tempsettings("
            "'id' INTEGER "
            "'user' TEXT,"
            "'company' TEXT,"
            "'url' TEXT)")
        .catchError((error) => print(error.toString()));
    await db.execute(
        "INSERT INTO tempsettings('id', 'user', 'company', 'url') SELECT 'id', 'user', 'company', 'url' FROM settings")
        .catchError((error) => print(error.toString()));

Does anyone could help me how to do this INSERT?

Thanks.

标签: fluttersqflite

解决方案


创建 id 列后,您缺少逗号

await db.execute("CREATE TABLE tempsettings("
            "id INTEGER ", //this comma was missing
            "user TEXT,"
            "company TEXT,"
            "url TEXT)")
        .catchError((error) => print(error.toString()));

推荐阅读