-
I am getting this error on insert ] Unhandled Exception: SqliteException(1): while preparing statement, no such column: message_index, SQL logic error (code 1)
E/flutter ( 7727): Causing statement: INSERT INTO "chats" ("id", "last_access_time") VALUES (?, ?) The error is being caused by a trigger: CREATE TRIGGER IF NOT EXISTS insert_system_message
AFTER INSERT ON chats
BEGIN
INSERT INTO messages (role,content,messages.message_index,"chat_id")
VALUES('system' ,'You are a helpful chat bot that limits your responses to 300 characters.' ,0 , NEW.id);
END; However the
class Messages extends Table {
IntColumn get id => integer().autoIncrement()();
TextColumn get role => text()();
TextColumn get content => text()();
IntColumn get messageIndex => integer().nullable()();
TextColumn get chatId => text().references(Chats, #id)();
IntColumn get previousMessage =>
integer().nullable().references(Messages, #id)();
}
class Message extends DataClass implements Insertable<Message> {
final int id;
final String role;
final String content;
final int? messageIndex;
final String chatId;
final int? previousMessage;
const Message(
{required this.id,
required this.role,
required this.content,
this.messageIndex,
required this.chatId,
this.previousMessage});
@override
Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{};
map['id'] = Variable<int>(id);
map['role'] = Variable<String>(role);
map['content'] = Variable<String>(content);
if (!nullToAbsent || messageIndex != null) {
map['message_index'] = Variable<int>(messageIndex);
}
map['chat_id'] = Variable<String>(chatId);
if (!nullToAbsent || previousMessage != null) {
map['previous_message'] = Variable<int>(previousMessage);
}
return map;
} |
Beta Was this translation helpful? Give feedback.
Answered by
muddi900
Oct 11, 2023
Replies: 1 comment 12 replies
-
Has |
Beta Was this translation helpful? Give feedback.
12 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I figured it out. The PRAGMA output shows that the field is nullable
Apparently initiating a nullable field in an insert statement throws this error. This true for running a purely sql runtime.