Deleting A Column In Table.

Hi all,

I am a newbie to YII.

I have a small doubt…

I have created a table and related models and crud. I have started working with my crud and later dropped down few columns of my original table.

This is creating a problem in my yii…is that not allowed? I have not written any code related to the columns which I have deleted.


can i know how do you created CRUD code for your table?

If u have used gii tool, it will automatically create code for all columns…

when u remove some column in your table… you have to remove some code from




I hope it will help you

yea i have use gii to create my crud.

can u plz help me where exact should I delete my code in MVC


I cannot help without viewing your code…

Please copy your code… i will tell you where you have to do some change …

Its really hard to explaing without seeing code.


I have attached my MVC Files here.

Please help


details about which column did u removed from your table?


I have this following table


I have deleted the last 4 columns: name,type,size,content.

As far I know YII…I have not written any code for these columns, it must have been included somewhere and I am not able to indentify.

[size="3"]Delete from your Event.php[/size]

 * @property string $evenue

 * @property string $econtact

[s] * @property string $name

  • @property string $type

  • @property integer $size

  • @property string $content[/s]


class Event extends CActiveRecord


[size="3"]Your rules function, search for name, search for type,size and content and delete everything you found. Here i searched for name and marked for you the 3 lines which needed to be edited.[/size]

public function rules()


		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.

		return array(

			array('size', 'numerical', 'integerOnly'=>true),



 type', 'length', 'max'=>30),


			array('econtact','match','not'=>false,'pattern'=>'/^[7-9]{1}[0-9]{9}$/','message'=>'Invalid Mobile'),

			array('etime', 'length', 'max'=>5),

			array('etime','match','not'=>false,'pattern'=>'/([0-1]\d|2[0-3])<img src='' class='bbc_emoticon' alt=':(' />[0-5]\d)/','message'=>'Invalid Mobile'),


array(‘name’, ‘file’,‘types’=>‘jpg, gif, png’, ‘allowEmpty’=>true, ‘on’=>‘update’),

			array('evenue', 'length', 'max'=>50),

			array('econtact', 'length', 'max'=>10),

			array('edate, content', 'safe'),

			// The following rule is used by search().

			// @todo Please remove those attributes that should not be searched.

			array('ename, edate, etime, evenue, econtact,


 type, size, content', 'safe', 'on'=>'search'),


			array('ename', 'unique', 'on' => 'insert,update', 'message' => 'This event has already been created!'),



Delete in your

public function attributeLabels()


		return array(

			'ename' => 'Ename',

			'edate' => 'Edate',

			'etime' => 'Etime',

			'evenue' => 'Evenue',

			'econtact' => 'Econtact',

			'name' => 'Name', #delete it

			'type' => 'Type',#delete it

			'size' => 'Size',#delete it

			'content' => 'Content',#delete it




public function search()


		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;






		$criteria->compare('name',$this->name,true);  #delete it

		$criteria->compare('type',$this->type,true); #delete it

		$criteria->compare('size',$this->size);      #delete it

		$criteria->compare('content',$this->content,true);  #delete it


Delete in your _form.php the lines 114 to 116:

[s]echo $form->labelEx($model, ‘name’);

echo $form->fileField($model, ‘name’);

echo $form->error($model, ‘name’);[/s]

If you don’t have a name property in your class, you shouldn’t create a fileField etc.

Your actionCreate() asks for your name property!


$model->name = $fileName;

and here you are redirecting with your ename property


Change the lines.

public function actionCreate()


		$model=new Event;



		// Uncomment the following line if AJAX validation is needed

		 //$this->performAjaxValidation($model);// AJAX VALIDATION




			$rnd = rand(0,9999);


		   	$fileName = "{$rnd}-{$uploadedFile}";  // random number + file name

		    	$model->name = $fileName;