Unable to set foreign key SQLite.swift

785 views Asked by At

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

There are 1 answers

0
Inder Kumar Rathore On BEST ANSWER

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)