Search code examples
iosswiftsqlitesqlite.swift

Unable to set foreign key SQLite.swift


I am not able to set foreign key using stephencelis SQLite.swift.

t.foreignKey(user_id, references:"user_mstr",user_id)

I have two tables user_master and user_details. How to set user_id as a foreign key in user_detail table. I am getting below error.

Cannot invoke foreignkey with an arguement list of type (Expression<string>), 

Solution

  • You're passing string to references. It should be like

    let user_id = Expression<String>("user_id")
    
    let user_mstr = Table("user_mstr")
    
    //cate t somehow
    
    t.foreignKey(user_id, references: user_mstr, user_id)