title: Why does this ActiveRecord::save successfully save the model?
body: <pre><code>$model-save()
  </code></pre>
  
  <p>Returns <code>true</code> and row is added to database. But I don't have field default values in database. What's wrong? THere is Action Controller and Scheme DB and Model ActiveRecord</p>
  
  <p>Action Controller</p>
  
  <pre><code>public function actionCreate()
  {
      $model = new Requests();
      $model-&gt;user_id = null;
  
      if ($model-&gt;load(Yii::$app-&gt;request-&gt;post()) &amp;&amp; $model-&gt;save()) {
  
          Yii::$app-&gt;response-&gt;format = Response::FORMAT_JSON;
  
          $response = [
              'id'  =&gt; $model-&gt;id,
              'url' =&gt; 'request-lease/'.$model-&gt;url,
          ];
  
          return $response;
  
      } else {
          return BaseHtml::errorSummary($model, ['class' =&gt; 'alert alert-danger']);
      }
  }
  </code></pre>
  
  <p>Model ACtiveRecord</p>
  
  <pre><code>class Requests extends \yii\db\ActiveRecord
   {
  /** Inactive status */
  const STATUS_UNVERIFIED = 0;
  /** Active status */
  const STATUS_ACTIVE = 1;
  /** Blocked status */
  const STATUS_BLOCKED = 3;
  /** Deleted status */
  const STATUS_DELETED = 5;
  /** Expired status */
  const STATUS_EXPIRED = 6;
  
  /**
   * Finance Array
   */
  public static $trade_finance_arr = [
      1 =&gt; 'Leased',
      2 =&gt; 'Financed',
      3 =&gt; 'Owned',
      4 =&gt; 'Other'
  ];
  
  /**
   * Trade condition array
   */
  public static $trade_condition_arr = [
      1 =&gt; 'Excellent',
      2 =&gt; 'Good',
      3 =&gt; 'Fair',
      4 =&gt; 'Poor'
  ];
  
  
  /**
   * @var string Model status.
   */
  private $_status;
  
  private $_credit_score;
  
  public $offersCount;
  
  /**
   * @inheritdoc
   */
  public static function tableName()
  {
      return '{{%carbuilder_requests}}';
  }
  
  /**
   * @inheritdoc
   */
  public function behaviors()
  {
      return [
          'timestampBehavior' =&gt; [
              'class' =&gt; TimestampBehavior::className(),
          ],
      ];
  }
  
  /**
   * @inheritdoc
   */
  public function rules()
  {
      return [
  //            [['user_id', 'vin', 'miles', 'zip', 'exterior_color', 'interior_color', 'comments', 'miles_per_year', 'started', 'term', 'credit_company', 'url', 'packages_ids', 'options_ids', 'created_at', 'updated_at', 'total_msrp', 'styleId'], 'required'],
          [['user_id', 'zip', 'miles_per_year', 'started', 'term',
              'credit_company', 'status_id', 'created_at', 'updated_at', 'total_msrp', 'styleId',
              'trade_finance','trade_bank','trade_term','trade_miles', 'trade_condition',
              'credit_score'], 'integer'],
          [['vin'], 'string', 'max' =&gt; 17],
          [['name', 'surname'], 'string', 'max' =&gt; 50],
          [['phone'], 'string', 'max' =&gt; 30],
          [['exterior_color', 'interior_color'], 'string', 'max' =&gt; 125],
          [['comments','trade_comments'], 'string', 'max' =&gt; 1000],
          [['url', 'pdf'], 'string', 'max' =&gt; 255],
          [['packages_ids', 'options_ids'], 'string', 'max' =&gt; 512],
          [['url'], 'unique'],
          [['income'], 'double']
          //[['user_id'], 'exist', 'skipOnError' =&gt; true, 'targetClass' =&gt; User::className(), 'targetAttribute' =&gt; ['user_id' =&gt; 'id']],
      ];
  }
  
  /**
   * @inheritdoc
   */
  public function attributeLabels()
  {
      return [
          'id' =&gt; 'ID',
          'user_id' =&gt; 'User ID',
          'vin' =&gt; 'Vin',
          'trade_miles' =&gt; 'Miles',
          'zip' =&gt; 'Zip',
          'exterior_color' =&gt; 'Exterior Color',
          'interior_color' =&gt; 'Interior Color',
          'comments' =&gt; 'Comments',
          'miles_per_year' =&gt; 'Miles Per Year',
          'started' =&gt; 'Started',
          'term' =&gt; 'Term',
          'credit_company' =&gt; 'Credit Company',
          'url' =&gt; 'Url',
          'status_id' =&gt; 'Status ID',
          'packages_ids' =&gt; 'Packages Ids',
          'options_ids' =&gt; 'Options Ids',
          'created_at' =&gt; 'Created At',
          'updated_at' =&gt; 'Updated At',
          'total_msrp' =&gt; 'Total Msrp',
          'styleId' =&gt; 'Style ID',
          'pdf' =&gt; 'PDF',
          'activation_at' =&gt; 'Activation At'
      ];
  }
  
  /**
   * @inheritdoc
   */
  public function beforeSave($insert)
  {
      if ($insert) {
          if ($this-&gt;user_id === null) {
              $this-&gt;user_id = (Yii::$app-&gt;user-&gt;id) ? Yii::$app-&gt;user-&gt;id : 0;
          }
      }
  
      return parent::beforeSave($insert);
  }
  
  /**
   * @inheritdoc
   */
  public function afterSave($insert, $changedAttributes)
  {
      if ($insert) {
          $this-&gt;setUrl();
      }
  
      parent::afterSave($insert, $changedAttributes);
  }
  
  public static function findRequestbyUrl($node){
  
  
      return self::find()-&gt;where(['url'=&gt;$node])-&gt;one();
  
  }
  
  /**
   * @return \yii\db\ActiveQuery
   */
  public function getOffers()
  {
      return $this-&gt;hasMany(Offers::className(), ['request_id' =&gt; 'id']);
  }
  
  /**
   * @return \yii\db\ActiveQuery
   */
  public function getOffer()
  {
      return $this-&gt;hasOne(Offers::className(), ['request_id' =&gt; 'id'])
          -&gt;where(['user_id' =&gt; Yii::$app-&gt;user-&gt;id])
          -&gt;inverseOf('request');
  }
  
  /**
   * @return \yii\db\ActiveQuery
   */
  public function getUser()
  {
      return $this-&gt;hasOne(User::className(), ['id' =&gt; 'user_id']);
  }
  
  /**
   * @return \yii\db\ActiveQuery
   */
  public function getVehicle()
  {
      return $this-&gt;hasOne(Vehicle::className(), ['styleId' =&gt; 'styleId']);
  }
  
  /**
   * @return \yii\db\ActiveQuery
   */
  public function getBank()
  {
      return $this-&gt;hasOne(CreditCompany::className(), ['id' =&gt; 'trade_bank']);
  }
  
  /**
   * @return integer
   */
  public function getNewCountMessages()
  {
      $count = 0;
      foreach($this-&gt;offers as $offer) {
          $count += $offer-&gt;newCountMessages;
      }
      return $count;
  }
  
  /**
   * @return \yii\db\ActiveQuery
   */
  public function getPackages()
  {
      if(empty($this-&gt;packages_ids)) return false;
      $packages = rtrim($this-&gt;packages_ids, ',');
      $packages = explode(',', $packages);
      return PackageOptions::find()-&gt;where(['optionsId' =&gt; $packages, 'styleId' =&gt; $this-&gt;styleId])-&gt;groupBy(['optionsId','styleId'])-&gt;all();
  }
  
  /**
   * @return \yii\db\ActiveQuery
   */
  public function getOptions()
  {
      if(empty($this-&gt;options_ids)) return false;
      $options = rtrim($this-&gt;options_ids, ',');
      $options = explode(',', $options);
      return PackageOptions::find()-&gt;where(['optionsId' =&gt; $options, 'styleId' =&gt; $this-&gt;styleId])-&gt;groupBy(['optionsId','styleId'])-&gt;all();
  }
  /**
   * Change or create Request url
   * @param string|null $url Url of request
   * @return boolean true if lease url was successfully changed
   */
  public function setUrl($url = null)
  {
      if($url) {
          Route::saveUrl($url, 'carbuilder/requests/summary');
          $this-&gt;url = $url;
          return $this-&gt;save(false);
      }
  
      $url = Inflector::slug($this-&gt;vehicle-&gt;make . '-' . $this-&gt;vehicle-&gt;model . '-' . $this-&gt;vehicle-&gt;trim .  '-' . $this-&gt;vehicle-&gt;year . '-' . $this-&gt;exterior_color . '-' . $this-&gt;id );
  
      Route::saveUrl($url, 'carbuilder/requests/summary');
      $this-&gt;url = $url;
      return $this-&gt;save(false);
  }
  }
  </code></pre>
  
  <p>Scheme database</p>
  
  <pre><code>CREATE TABLE `lfl_carbuilder_requests` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `user_id` int(11) NOT NULL,
   `vin` varchar(17) NOT NULL,
   `zip` int(5) NOT NULL,
   `exterior_color` varchar(125) NOT NULL,
    `interior_color` varchar(125) NOT NULL,
    `comments` varchar(1000) NOT NULL,
    `miles_per_year` int(5) NOT NULL,
    `started` int(11) NOT NULL,
    `term` tinyint(2) NOT NULL,
    `credit_company` tinyint(4) NOT NULL,
    `url` varchar(255) NOT NULL,
    `status_id` tinyint(4) NOT NULL DEFAULT '0',
    `packages_ids` varchar(512) NOT NULL,
    `options_ids` varchar(512) NOT NULL,
    `created_at` int(11) NOT NULL,
    `updated_at` int(11) NOT NULL,
    `total_msrp` int(11) DEFAULT NULL,
    `styleId` varchar(20) NOT NULL,
    `pdf` varchar(255) NOT NULL,
    `trade_finance` int(2) NOT NULL,
    `trade_bank` int(4) NOT NULL,
    `trade_term` int(2) NOT NULL,
    `trade_miles` int(5) NOT NULL,
    `trade_condition` int(2) NOT NULL,
    `trade_comments` varchar(1000) NOT NULL,
    `name` varchar(50) DEFAULT NULL,
    `surname` varchar(50) DEFAULT NULL,
    `phone` varchar(30) DEFAULT NULL,
    `state` varchar(30) NOT NULL,
    `location` varchar(30) NOT NULL,
    `credit_score` tinyint(1) DEFAULT NULL,
    `income` double NOT NULL,
    `activation_at` int(11) DEFAULT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `url` (`url`),
    KEY `status_id` (`status_id`),
    KEY `styleId` (`styleId`),
    KEY `FK_users_requests` (`user_id`)
   ) ENGINE=InnoDB AUTO_INCREMENT=661 DEFAULT CHARSET=utf8
  </code></pre>
  
  <p>Post request</p>
  
  <pre><code>exterior_color:"Deep Sea Blue Metallic"
  interior_color:"Aluminum Hexagon W/Estoril Blue Matte Highlight"
  options_ids:""
  packages_ids:"200744520"
  request_id:0
  styleId:200744434
  total_msrp:41550
  user_id:0
  </code></pre>