drogonframework / drogon

Drogon: A C++14/17/20 based HTTP web application framework running on Linux/macOS/Unix/Windows
MIT License
11.06k stars 1.06k forks source link

Error Assertion `dbClientsMap_.find(name) != dbClientsMap_.end()' failed. #1959

Closed minhhoai1001 closed 4 months ago

minhhoai1001 commented 4 months ago

I using drogon on Ubuntu 20.04.

auto dbClient = app().getDbClient();
auto teacherMapper = drogon::orm::Mapper<Teachers>(dbClient);
std::vector<Teachers> teachers = teacherMapper.findAll();
for(const auto& teacher : teachers)
{
    int64_t id = teacher.getValueOfId();
    std::cout << "ID: " << id << std::endl;
    std::cout << "First name: " << teacher.getValueOfFirstName() << std::endl;
}

I got error: drogon-web: /home/hoai-tran/Documents/study/drogon/lib/src/DbClientManager.h:36: drogon::orm::DbClientPtr drogon::orm::DbClientManager::getDbClient(const string&): Assertion `dbClientsMap.find(name) != dbClientsMap.end()' failed. Aborted (core dumped)

Help me how to fix it.

an-tao commented 4 months ago

Did you add dbclient in the configuration file? please paste it here.

minhhoai1001 commented 4 months ago

Thank you. I forgot uncomment "db_clients" in config.json. It work now.