Generating Code with Gii - CRUD TUT not working.

Hi Everyone,

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.



Hello Clay, did you modify your db.php according to your database name in your config folder?

Is {{%country_search}} in your \models\CountrySearch.php or where did you get that message???

CountrySearch is no database table. It´s a "help" model for searching in the Country table generated by gii…

Thanks yiim and Simplicity

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 :

  1. You are using advanced template, in that case you need to update namespaces too in gii,

  2. folders: models, views and controllers are not writable, in that case you need to make them writable first.

Thanks Nenad

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.

Please check if CountrySearch is extending from Country model.

Also, you say that you get some error when you run application. What error ?

Yes the CountrySearch model extends the Country model

It shows that the table CountrySearch does not exist.

Invalid Configuration – yii\base\InvalidConfigException

The table does not exist: {{%country_search}}

Well it shouldn’t exist… CountrySearch is extending from Country, and Country should have method

public static function tableName()


    return '{{%country}}';


I don’t know, this is weird…

That is my thought as well.

I am going to try another example that I am making up for an Item model. See if I have the same issue.

Thanks appreciate the help

Ok just created a table Item and followed the same process and everything worked fine.

I am going to delete the files for Country and try it again. Must have been something quirky happening when I ran the CRUD for Country.

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.

Thanks Everyone appreciate the support!!!

Same issue here… problem was that Country.php model needs the method added:

public static function tableName()


return ‘{{%country}}’;


It is not clear from the tutorial that you need to do this. They may want to edit the instructions.

@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 ?