Skip to content

Weird exception message when table don't exists #79

@rufanov

Description

@rufanov

Hello!

A friend of mine created simple application that use nette/database. In controller action he has this code:

$clients = $db->table('clients');
$client = $db->get($id);

At first time it worked fine. But later he started to want to rename 'clients' to 'users' . So he changed table name in database, and changed code:

$users = $db->table('users');
$user = $db->get($id);

Seems fine, but.. He got exception:

LogicException
Table 'users' does not have a primary key.

What?!? He looked at database structure, and said "but i have primary key in this table!".

Then he looked at Nette.Database.Structure cache and found real problem - there is no any data about table named 'users'. So he removed this cache to rebuild it, and after this application started to work fine again.

I tried to use table that really don't exists in database:

$db->table('foobar')->get(1);

and got same exception:

Table 'foobar' does not have a primary key.

This is very strange behavior to show this exception message, isn't? I think if table actually exists in database but not present in cache, then nette/database should rebuild cache. Or, if not, then it should throw more meaningful exception like "Table don't exists".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions