初始化基本表时出现sqfline错误

时间:2019-07-29 12:12:37

标签: flutter sqflite

我正在尝试将SQFlite添加到我的flutter项目中。但是在初始化数据库时,出现以下错误。

E/SQLiteLog(26082): (1) near "references": syntax error
I/flutter (26082): error DatabaseException(near "references": syntax error (code 1): , while compiling: CREATE TABLE cv (
I/flutter (26082):             id INTEGER PRIMARY KEY,
I/flutter (26082):             name TEXT NOT NULL,
I/flutter (26082):             image TEXT NOT NULL,
I/flutter (26082):             signature TEXT NOT NULL,
I/flutter (26082):             skills TEXT NOT NULL,
I/flutter (26082):             address TEXT NOT NULL,
I/flutter (26082):             country TEXT NOT NULL,
I/flutter (26082):             education TEXT NOT NULL,
I/flutter (26082):             email TEXT NOT NULL,
I/flutter (26082):             phone TEXT NOT NULL,
I/flutter (26082):             objective TEXT NOT NULL,
I/flutter (26082):             references TEXT NOT NULL,
I/flutter (26082):             experience TEXT NOT NULL,
I/flutter (26082):           )) during open, closing...
E/flutter (26082): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: DatabaseException(near "references": syntax error (code 1): , while compiling: CREATE TABLE cv (
E/flutter (26082):             id INTEGER PRIMARY KEY,
E/flutter (26082):             name TEXT NOT NULL,
E/flutter (26082):             image TEXT NOT NULL,
E/flutter (26082):             signature TEXT NOT NULL,
E/flutter (26082):             skills TEXT NOT NULL,
E/flutter (26082):             address TEXT NOT NULL,
E/flutter (26082):             country TEXT NOT NULL,
E/flutter (26082):             education TEXT NOT NULL,
E/flutter (26082):             email TEXT NOT NULL,
E/flutter (26082):             phone TEXT NOT NULL,
E/flutter (26082):             objective TEXT NOT NULL,
E/flutter (26082):             references TEXT NOT NULL,
E/flutter (26082):             experience TEXT NOT NULL,
E/flutter (26082):           ))
E/flutter (26082): #0      wrapDatabaseException (package:sqflite/src/exception_impl.dart:11:7)
E/flutter (26082): <asynchronous suspension>
E/flutter (26082): #1      SqfliteDatabaseFactoryImpl.wrapDatabaseException (package:sqflite/src/factory_impl.dart:29:7)
E/flutter (26082): #2      _SqfliteDatabaseBase&Object&SqfliteDatabaseMixin.safeInvokeMethod (package:sqflite/src/database_mixin.dart:183:15)
E/flutter (26082): #3      _SqfliteDatabaseBase&Object&SqfliteDatabaseMixin.invokeExecute (package:sqflite/src/database_mixin.dart:328:12)
E/flutter (26082): #4      _SqfliteDatabaseBase&Object&SqfliteDatabaseMixin.txnExecute.<anonymous closure> (package:sqflite/src/database_mixin.dart:323:14)
E/flutter (26082): #5      _SqfliteDatabaseBase&Object&SqfliteDatabaseMixin.txnSynchronized (package:sqflite/src/database_mixin.dart:275:26)
E/flutter (26082): <asynchronous suspension>
E/flutter (26082): #6      _SqfliteDatabaseBase&Object&SqfliteDatabaseMixin.txnWriteSynchronized (package:sqflite/src/database_mixin.dart:307:7)
E/flutter (26082): #7      _SqfliteDatabaseBase&Object&SqfliteDatabaseMixin.txnExecute (package:sqflite/src/database_mixin.dart:313:12)
E/flutter (26082): #8      _SqfliteDatabaseBase&Object&SqfliteDatabaseMixin&SqfliteDatabaseExecutorMixin.execute (package:sqflite/src/database_mixin.dart:35:15)
E/flutter (26082): #9      DatabaseHelper._onCreate (package:cv_builder/db_helper.dart:35:14)
E/flutter (26082): <asynchronous suspension>
E/flutter (26082): #10     _SqfliteDatabaseBase&Object&SqfliteDatabaseMixin.doOpen.<anonymous closure> (package:sqflite/src/database_mixin.dart:661:29)
E/flutter (26082): <asynchronous suspension>
E/flutter (26082): #11     _SqfliteDatabaseBase&Object&SqfliteDatabaseMixin._runTransaction (package:sqflite/src/database_mixin.dart:433:28)
E/flutter (26082): <asynchronous suspension>
E/flutter (26082): #12     _SqfliteDatabaseBase&Object&SqfliteDatabaseMixin.transaction.<anonymous closure> (package:sqflite/src/database_mixin.dart:450:14)
E/flutter (26082): <asynchronous suspension>
E/flutter (26082): #13     _SqfliteDatabaseBase&Object&SqfliteDatabaseMixin.txnSynchronized (package:sqflite/src/database_mixin.dart:275:26)
E/flutter (26082): <asynchronous suspension>
E/flutter (26082): #14     _SqfliteDatabaseBase&Object&SqfliteDatabaseMixin.txnWriteSynchronized (package:sqflite/src/database_mixin.dart:307:7)
E/flutter (26082): #15     _SqfliteDatabaseBase&Object&SqfliteDatabaseMixin.transaction (package:sqflite/src/database_mixin.dart:449:12)
E/flutter (26082): #16     _SqfliteDatabaseBase&Object&SqfliteDatabaseMixin.doOpen (package:sqflite/src/database_mixin.dart:651:15)
E/flutter (26082): <asynchronous suspension>
E/flutter (26082): #17     SqfliteDatabaseOpenHelper.openDatabase (package:sqflite/src/database.dart:32:22)
E/flutter (26082): <asynchronous suspension>
E/flutter (26082): #18     _SqfliteDatabaseFactoryImpl&Object&SqfliteDatabaseFactoryMixin.openDatabase.<anonymous closure> (package:sqflite/src/factory_mixin.dart:100:43)
E/flutter (26082): <asynchronous suspension>
E/flutter (26082): #19     ReentrantLock.synchronized.<anonymous closure>.<anonymous closure> (package:synchronized/src/reentrant_lock.dart:33:24)
E/flutter (26082): #20     _rootRun (dart:async/zone.dart:1124:13)
E/flutter (26082): #21     _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter (26082): #22     _runZoned (dart:async/zone.dart:1516:10)
E/flutter (26082): #23     runZoned (dart:async/zone.dart:1463:12)
E/flutter (26082): #24     ReentrantLock.synchronized.<anonymous closure> (package:synchronized/src/reentrant_lock.dart:32:24)
E/flutter (26082): <asynchronous suspension>
E/flutter (26082): #25     BasicLock.synchronized (package:synchronized/src/basic_lock.dart:31:26)
E/flutter (26082): <asynchronous suspension>
E/flutter (26082): #26     ReentrantLock.synchronized (package:synchronized/src/reentrant_lock.dart:28:17)
E/flutter (26082): <asynchronous suspension>
E/flutter (26082): #27     _SqfliteDatabaseFactoryImpl&Object&SqfliteDatabaseFactoryMixin.openDatabase (package:sqflite/src/factory_mixin.dart:66:17)
E/flutter (26082): #28     openDatabase (package:sqflite/sqflite.dart:150:26)
E/flutter (26082): #29     DatabaseHelper._initDatabase (

可能是什么问题?

2 个答案:

答案 0 :(得分:1)

在SQL查询的最后一行experience TEXT NOT NULL, 将其更新为experience TEXT NOT NULL 删除逗号,

答案 1 :(得分:0)

当然,此解决方案可以解决您的问题,但是在我的情况下并非如此。我的语法正确。我的查询很大,因此编译器导致错误。刚刚解决了将查询分为字符串变量然后传递给数据库查询功能的问题。

例如,

这将导致错误。



await db.execute('''
CREATE TABLE TEST(.................
..................)
''');



解决方案:

String query='''
CREATE TABLE TEST(.................
..................)
''';

await db.execute(query);