Sqlite.swift: Error when try to addColumn: Cannot convert value of type 'Expression<String>' to expected argument type 'Expression<_?>'

Created on 29 Jan 2018  路  1Comment  路  Source: stephencelis/SQLite.swift

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("username")
static let DATE_INIT = Expression("date_init")
static let EXPIRATION = Expression("expiration")
static let TIMEZONE = Expression("timezone")
static let ID = Expression("alert_id")
static let TITLE = Expression("title")
static let DATA = Expression("data")
static let READ = Expression("read")
static let RECEIPT_DATE = Expression("receipt_date")
static let RECEIPT_DATE_TIMEZONE = Expression("receipt_date_tz")
static let PROCESSED = Expression("processed")`

The error: Cannot convert value of type 'Expression' to expected argument type 'Expression<_?>

I don't not why happen this...help pls!

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)))

>All comments

I solve by modify this: try! db?.run(palerts.addColumn(TPAlert.DATE_INIT)) TO try! db?.run(palerts.addColumn(Expression(TPAlert.DATE_INIT)))

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Tchoupinax picture Tchoupinax  路  8Comments

hansrajgavali picture hansrajgavali  路  3Comments

bgdnr picture bgdnr  路  7Comments

Viswanth92 picture Viswanth92  路  3Comments

arnoldschmid picture arnoldschmid  路  4Comments