Aaron Gallick Aaron Gallick - 6 months ago 15
SQL Question

SQLSTATE[23000]: Integrity constraint violation

Okay so i'm trying to add a new team into my 'teams' column on my database, however I am getting this error [QueryException","message":"SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null (SQL: insert into

teams
(
name
,
game
) ]

This is the HTML -

<form ng-submit="addteam()" ng-model="teamform">
<h2>Add Team</h2>
<label>
Team Name
<input type="text" ng-model="teamform.name"/>
</label>
<label>
Game
<select ng-model="teamform.game">
<option ng-repeat="game in games" value="{{game.gameID}}">{{game.game_name}}</option>
</select>
</label>
<input value="submit" type="submit"/>
</form>




This is the Service -

addteam:function(form){
var call = Phone.call('api/team/insert', form);
call.success(function(data) {
Flash.show('Team Created');
});
call.error(function() {
});

return call;
}


This is the Controller -

$scope.addteam = function(){
PanelService.addteam($scope.teamform);
};


This is the TeamController -

public function insertTeam(){
Team::insertGetId(array(
'name'=>Input::get('name'),
'game'=>Input::get('game')
));
}


Any help will be much appreciated!

Answer

Try to add this in your controller

$scope.teamform = {}