Fresh newbie here. I have experience with MVC but brand new to Yii.
Working my way through the 2.0 Guide and I am currently doing the Gii CRUD generator and I get the following error
The table does not exist: {{%country_search}}
I have followed the steps exactly and when I try again it shows everything as unchanged. Is it intended to create a country_search table? I check and the table doesn’t exist.
So far I have liked what I see, but as I am new and haven’t played around a lot yet I am stumped. Any help would be greatly appreciated.
In the tutorial (2.0 Guide - Getting Started - Generating code with Gii)it walks you through CRUD Generation using an example of Country / CountrySearch / CountryController.
I have followed the example and when I go to the URL to see the example in action I get the error.
I have setup the db as I previously went through the Model Generator in the same tut. Did not have any issues until the generate code with GII / CRUD Generation tutorial.
Gii is not supposed to create database or tables. You have to create them before you start using gii. In this tutorial you should first create Country model that is representing country table. Then, when you create CRUD, Gii will create additional model CountrySearch that should extend from Country model, plus it will create CountryController and appropriate views. Guide is good, and if you follow it correctly everything should work, except if :
You are using advanced template, in that case you need to update namespaces too in gii,
folders: models, views and controllers are not writable, in that case you need to make them writable first.
I think I will try my own example to see if I have a similar problem. I did create the Country table as part of a previous tutorial and the CRUD generator is able to write the files (can see them in the directory and have opened each of them to look at how they are setup).
I am using the basic template.
Not sure where I could be going wrong as there really isn’t much room for error in the tutorial. Fairly easy to follow. I have also redone the tutorial and it shows me that none of the files need to be updated.
Just deleted the files for Country and went through it again and it worked fine the second time. It is strange, didn’t do anything different. At least I got my first experience of trying to troubleshoot Yii… always valuable when looking at new frameworks.
@ajm0824 FWIW: I had the same issue but like Clayton I deleted the files and started over and during that confirmed that the model creation already creates that static function by default, so the instructions don’t need to be updated. I suspect my files became corrupted by other typos that I had done myself previously. Second time around, but without the typos, everything just worked.
I followed the tuto perfectly, and had the same error. I generated the CRUD several times with overwrite option checked, with a good database and without adding any personal code and the error persists.
Adding this method to the Country controller solved it:
public static function tableName()
{
return ‘{{%country}}’;
}
Strange, is’n it ?