Hi.. i have a error when try to update a existing table and add a column, can any one help me?
Here my code:
let palerts = Table(TPAlert.TABLE_NAME)
do {
let tableInfo = Array(try db!.prepare("PRAGMA table_info(palerts)"))
let foundColumn = tableInfo.filter {
col in col[2] as! String == "DATE_INIT"
}
if(foundColumn.count == 0){
try! db?.run(palerts.addColumn(TPAlert.DATE_INIT)) // on this line i have a error: Cannot convert value of type 'Expression<String>' to expected argument type 'Expression<_?>'
}
try db!.run(palerts.create(ifNotExists: true) { t in
t.column(TPAlert.ID, primaryKey: true)
t.column(TPAlert.USERNAME)
t.column(TPAlert.DATE_INIT)
t.column(TPAlert.EXPIRATION)
t.column(TPAlert.TIMEZONE)
t.column(TPAlert.TITLE)
t.column(TPAlert.DATA)
t.column(TPAlert.READ)
t.column(TPAlert.RECEIPT_DATE)
t.column(TPAlert.RECEIPT_DATE_TIMEZONE)
t.column(TPAlert.PROCESSED)
})
try db!.run(palerts.createIndex([TPAlert.EXPIRATION], unique: false, ifNotExists: true))
} catch SQLite.Result.error(let error){
Logger.error("No se pudo crear la table \(TLog.TABLE_NAME). Motivo: \(error.message)")
} catch {
Logger.error("No se pudo crear la table \(TLog.TABLE_NAME). Error general.")
}
This is my model:
static let TABLE_NAME = "palerts"
static let USERNAME = Expression
static let DATE_INIT = Expression
static let EXPIRATION = Expression
static let TIMEZONE = Expression
static let ID = Expression
static let TITLE = Expression
static let DATA = Expression
static let READ = Expression
static let RECEIPT_DATE = Expression
static let RECEIPT_DATE_TIMEZONE = Expression
static let PROCESSED = Expression
The error: Cannot convert value of type 'Expression
' to expected argument type 'Expression<_?>
I don't not why happen this...help pls!
I solve by modify this: try! db?.run(palerts.addColumn(TPAlert.DATE_INIT)) TO try! db?.run(palerts.addColumn(Expression
Most helpful comment
I solve by modify this: try! db?.run(palerts.addColumn(TPAlert.DATE_INIT)) TO try! db?.run(palerts.addColumn(Expression(TPAlert.DATE_INIT)))