Moved index declaration, added some check

Moved index declaration after attribut declaration to avoid syntax error : Key column 'whatever_index' doesn't exist in table

Added some check when there are no table in db that would fail.