It looks likes stores and models are defined before db connection. Can you define dbconnection outside

regApplication before store and model.