sanguina
(Bha100710)
February 23, 2013, 12:24pm
1
I m getting an error message that says
The table "{{messages}}" for active record class "Message" cannot be found in the database.
I have doubly cross checked - sql is running, the database is connected and there is a table named ‘messages’ in the db.
Is there a specific meaning of curly braces around table names like ‘{{tablename}}’?
Do i need to rename the table to add these two braces in each side ?
Any suggestions to correct this ?
thanks a lot !
sanguina
(Bha100710)
February 23, 2013, 6:51pm
3
thanks that indeed solved the issue for me.
though i still dont have a clue as to why it did
seenivasan
(Chellamnivas)
February 23, 2013, 7:12pm
4
Dear Friend
You might have done that after following the BLOG tutorial.
For example, if you have all the tables in database with prefix tbl_.
Then in your configurationfile you have to declare the tablePrefix property.
.....................................................................................
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=blog',
'emulatePrepare' => true,
'username' => 'root',
'password' => 'yourPassword',
'charset' => 'utf8',
'tablePrefix'=>'tbl_',// DECLARING THE PREFIX
),
Then in your model
Post.php
public function tableName()
{
return '{{post}}';
}
If you are not attaching any prefix and having a table like post ,then
method tableName is declared in the following way.
Post.php
public function tableName()
{
return 'post';
}
Regards.
jacmoe
(Jacob Moena)
February 23, 2013, 7:40pm
5
I think it’s because you haven’t followed good practice when naming your db tables.
Yii assumes that you use a singular name, like ‘user’, ‘message’, ‘page’, ‘link’, …
I often see people naming records in plural, but that is not the True Way.
jacmoe
(Jacob Moena)
February 23, 2013, 7:48pm
6
Think about it: what do you call a HAS_MANY relation to Message?
That’s right: ‘messages’.
sanguina
(Bha100710)
February 23, 2013, 9:04pm
7
@seenivasna - no i got this error message while adding an extension on private-messaging.
Going by your explanation, that means a table name in curly braces means - it refers to the prefix declared in the config file.good to know:)
@jacmoe :thanks for that feedback. i see your point… will ensure that with next project, i keep singular database names.
This is my first yii app and as i progress i am getting to know several things that could have been better done… keeping these experiences for the next project.