Yii Framework Forum: The Table "{{Messages}}" For Active Record Class "message" Cannot Be Found In The Database. - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

The Table "{{Messages}}" For Active Record Class "message" Cannot Be Found In The Database. Rate Topic: -----

#1 User is offline   sanguina 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 22-July 12

Posted 23 February 2013 - 07:24 AM

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 ! :)
until I become certain that there is no certainty.
0

#2 User is offline   ORey 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,703
  • Joined: 20-April 09
  • Location:Moscow, Russia

Posted 23 February 2013 - 09:30 AM

Take a look
http://www.yiiframew...n-the-database/

Also you can set table name explicitly, just add

public function tableName()
{
    return 'messages';
}


to your model.
God is real unless declared as integer
1

#3 User is offline   sanguina 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 22-July 12

Posted 23 February 2013 - 01:51 PM

thanks that indeed solved the issue for me.

though i still dont have a clue as to why it did :D
until I become certain that there is no certainty.
0

#4 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 23 February 2013 - 02:12 PM

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.
0

#5 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 3,326
  • Joined: 10-October 10
  • Location:Denmark

Posted 23 February 2013 - 02:40 PM

View Postsanguina, on 23 February 2013 - 01:51 PM, said:

thanks that indeed solved the issue for me.

though i still dont have a clue as to why it did :D


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. Posted Image
"Less noise - more signal"
0

#6 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 3,326
  • Joined: 10-October 10
  • Location:Denmark

Posted 23 February 2013 - 02:48 PM

Think about it: what do you call a HAS_MANY relation to Message?

That's right: 'messages'.
"Less noise - more signal"
0

#7 User is offline   sanguina 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 22-July 12

Posted 23 February 2013 - 04:04 PM

@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. :)
until I become certain that there is no certainty.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users