Newly added column is not being saved in DB

I have added a new field "sell_price_default" in my "Food" table. and then i manually added a variable for that field in my Model, added rules too. But value for that field "sell_price_default" is not being saved in DB. can anyone guide me what i am missing. below is my model




<?php


namespace app\models;


use Yii;

use yii\web\UploadedFile;


/**

 * This is the model class for table "food".

 *

 * @property integer $food_id

 * @property string $short_desp

 * @property string $long_desp

 * @property string $image_url

 * @property integer $fc_id

 * @property string $sell_price_default

 */

class Food extends \yii\db\ActiveRecord

{

    /**

     * @var UploadedFile|Null file attribute

     */

    public $file;

    

    /**

     * @var selling price default value.

     */

    public $sell_price_default;

    

    const SCENARIO_ADD = 'add_food';

    const SCENARIO_EDIT = 'edit_food';

    

    /**

     * @inheritdoc

     */

    public static function tableName()

    {

        return 'foods';

    }


   public function scenarios()

    {

        $scenarios = parent::scenarios();

        $scenarios[self::SCENARIO_ADD] = ['fc_id', 'short_desp', 'long_desp', 'file', 'sell_price_default'];

        $scenarios[self::SCENARIO_EDIT] = ['short_desp', 'long_desp', 'fc_id', 'sell_price_default'];

        

        return $scenarios;

    }

    

    

    /**

     * @inheritdoc

     */

    public function rules()

    {

        return [

            [['sell_price_default'], 'string'],

            [['short_desp', 'long_desp', 'fc_id', 'image_url', 'sell_price_default' ], 'required', 'on' => self::SCENARIO_ADD],

            [['short_desp', 'long_desp', 'fc_id', 'image_url', 'sell_price_default'], 'required', 'on' => self::SCENARIO_EDIT],


        ];

    }


    /**

     * @inheritdoc

     */

    public function attributeLabels()

    {

        return [

            'food_id' => 'Food ID',

            'short_desp' => 'Short Desp',

            'long_desp' => 'Long Desp',

            'image_url' => 'Image Url',

            'fc_id' => 'Fc ID',

            'sell_price_default' => 'Default Selling Price'

        ];

    }

}




Remove $sell_price_default property.

http://www.yiiframework.com/doc-2.0/guide-db-active-record.html#accessing-dataink

Hi,

Just try removing the following lines:

"sell_price_default" should not be declared like that, because it is a column-based attribute and should be reserved for the automatic handling by ActiveRecord, as you do with other ones like "food_id", "short_desp", "long_desp", and so on.

@softark , phtamas

I am very thankful to you, its resolved now. :)

However, i am another question

this field "sell_price_default" has "Float" data type in DB. so how i will define rules in my model. Because i cant find any validation rules for "Float".

number validator

http://www.yiiframework.com/doc-2.0/yii-validators-numbervalidator.html

Thanks , its working as per my requirements. :)