foreign keys sql generation some progress