Error: SQLSTATE[HY000]: General error: 1364 Field ‘sale_phase_id’ doesn’t have a default value
Why Im I getting this
LeadsTable.php
public function initialize(array $config)
{
parent::initialize($config);
$this->setTable('leads');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
$this->addBehavior('Timestamp');
$this->belongsTo('SalePhases', [
'foreignKey' => 'sale_phase_id',
'joinType' => 'INNER'
]);
$this->belongsTo('Campaigns', [
'foreignKey' => 'campaign_id',
'joinType' => 'INNER'
]);
$this->belongsTo('Users', [
'foreignKey' => 'user_id',
'joinType' => 'INNER'
]);
$this->belongsTo('Accounts', [
'foreignKey' => 'account_id',
'joinType' => 'INNER'
]);
$this->belongsTo('Contacts', [
'foreignKey' => 'contact_id',
'joinType' => 'INNER'
]);
$this->belongsTo('PaidTo', [
'foreignKey' => 'paid_to_id',
'joinType' => 'INNER'
]);
$this->belongsTo('Secteurs', [
'foreignKey' => 'secteur_id',
'joinType' => 'INNER'
]);
$this->belongsToMany('Leads', [
'foreignKey' => 'lead_type_id',
'joinType' => 'INNER'
]);
$this->belongsTo('SourceProspects', [
'foreignKey' => 'source_prospect_id',
'joinType' => 'INNER'
]);
$this->hasMany('Accounts', [
'foreignKey' => 'lead_id'
]);
$this->hasMany('Contacts', [
'foreignKey' => 'lead_id'
]);
}
public function validationDefault(Validator $validator)
{
$validator
->integer('id')
->allowEmpty('id', 'create');
$validator
->scalar('name_lead')
->maxLength('name_lead', 255)
->requirePresence('name_lead', 'create')
->notEmpty('name_lead');
$validator
->integer('forcecast_amount')
->requirePresence('forcecast_amount', 'create')
->notEmpty('forcecast_amount');
$validator
->date('term')
->requirePresence('term', 'create')
->notEmpty('term');
$validator
->scalar('next')
->maxLength('next', 255)
->requirePresence('next', 'create')
->notEmpty('next');
$validator
->numeric('probability')
->requirePresence('probability', 'create')
->notEmpty('probability');
$validator
->scalar('description')
->maxLength('description', 255)
->requirePresence('description', 'create')
->notEmpty('description');
return $validator;
}
public function buildRules(RulesChecker $rules)
{
$rules->add($rules->existsIn(['sale_phase_id'], 'SalePhases'));
$rules->add($rules->existsIn(['campaign_id'], 'Campaigns'));
$rules->add($rules->existsIn(['user_id'], 'Users'));
$rules->add($rules->existsIn(['account_id'], 'Accounts'));
$rules->add($rules->existsIn(['contact_id'], 'Contacts'));
$rules->add($rules->existsIn(['paid_to_id'], 'PaidTo'));
$rules->add($rules->existsIn(['secteur_id'], 'Secteurs'));
$rules->add($rules->existsIn(['lead_type_id'], 'Leads'));
$rules->add($rules->existsIn(['source_prospect_id'], 'SourceProspects'));
return $rules;
}
}
SalePhasesTable.php
public function initialize(array $config)
{
parent::initialize($config);
$this->setTable('sale_phases');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
$this->belongsTo('Users', [
'foreignKey' => 'user_id'
]);
$this->hasMany('Leads', [
'foreignKey' => 'sale_phase_id'
]);
}
public function validationDefault(Validator $validator)
{
$validator
->integer('id')
->allowEmpty('id', 'create');
$validator
->scalar('name_phase')
->maxLength('name_phase', 25)
->allowEmpty('name_phase');
return $validator;
}
public function buildRules(RulesChecker $rules)
{
$rules->add($rules->existsIn(['user_id'], 'Users'));
return $rules;
}
}