Laravel primary key does not allow null












-1















i"m using laravel+Nova, connecting to existing database of an existing software. The primary key is not the deault "ID" so at the "model" i changed it to like that:



<?php

namespace App;

use IlluminateDatabaseEloquentModel;

class products extends Model
{
//
protected $table = 't_items';
protected $primaryKey = 'item_num';

public $timestamps = false;

}


=============================================================
When changing and updating the satabase (With nova) there is no error.
However when using save (for new or existing row) there is an error:



SQLSTATE[42000]:[Microsoft][ODBC Driver 13 forSQL Server][SQL Server] Error converting data type nvarchar to numeric 9SQL select top 1 * drom [t_items][item_num] = null

"item_num" is defined as:
numeric
primary key
Allo nulls = false
Identity = false
Identity seed = 0
Identity increment = 0
Length = 9
Numeric precision = 10
Numeric scale = 0


What should i add. i think laravel soed not defining the ID when saving and the server needs it










share|improve this question























  • Hi David, i saw Error converting data type nvarchar to numeric in the error message. could you turn off the auto increments of the primary key using $incrementing = false on the model?

    – Bagus Tesa
    Dec 31 '18 at 23:15











  • i tried it. still get this error: SQLSTATE[42000]:[Microsoft][ODBC Driver 13 for SQL Server][SQL Server] Cannot insert the value NULL into column 'item_num'....

    – David Gabbay
    Jan 1 at 6:26











  • Cannot insert the value NULL into column 'item_num'. hold on David, could you post how you insert the data? after settings $incrementing to false you had always to assign the primary key manually whenever you save new model..

    – Bagus Tesa
    Jan 1 at 7:35











  • nova does not ask for id when create a new row. i dont fined how to make it ask for it. Though i added required to this field at App/Nova/Produccts php like so: public function fields(Request $request) { return [ ID::make('ID', 'item_num') ->creationRules('required') ->sortable(), Text::make('item_name') ]; }

    – David Gabbay
    Jan 1 at 22:45













  • i now see this issue happened to others but was not answered nor solved at github: github.com/laravel/nova-issues/issues/734

    – David Gabbay
    Jan 1 at 22:47
















-1















i"m using laravel+Nova, connecting to existing database of an existing software. The primary key is not the deault "ID" so at the "model" i changed it to like that:



<?php

namespace App;

use IlluminateDatabaseEloquentModel;

class products extends Model
{
//
protected $table = 't_items';
protected $primaryKey = 'item_num';

public $timestamps = false;

}


=============================================================
When changing and updating the satabase (With nova) there is no error.
However when using save (for new or existing row) there is an error:



SQLSTATE[42000]:[Microsoft][ODBC Driver 13 forSQL Server][SQL Server] Error converting data type nvarchar to numeric 9SQL select top 1 * drom [t_items][item_num] = null

"item_num" is defined as:
numeric
primary key
Allo nulls = false
Identity = false
Identity seed = 0
Identity increment = 0
Length = 9
Numeric precision = 10
Numeric scale = 0


What should i add. i think laravel soed not defining the ID when saving and the server needs it










share|improve this question























  • Hi David, i saw Error converting data type nvarchar to numeric in the error message. could you turn off the auto increments of the primary key using $incrementing = false on the model?

    – Bagus Tesa
    Dec 31 '18 at 23:15











  • i tried it. still get this error: SQLSTATE[42000]:[Microsoft][ODBC Driver 13 for SQL Server][SQL Server] Cannot insert the value NULL into column 'item_num'....

    – David Gabbay
    Jan 1 at 6:26











  • Cannot insert the value NULL into column 'item_num'. hold on David, could you post how you insert the data? after settings $incrementing to false you had always to assign the primary key manually whenever you save new model..

    – Bagus Tesa
    Jan 1 at 7:35











  • nova does not ask for id when create a new row. i dont fined how to make it ask for it. Though i added required to this field at App/Nova/Produccts php like so: public function fields(Request $request) { return [ ID::make('ID', 'item_num') ->creationRules('required') ->sortable(), Text::make('item_name') ]; }

    – David Gabbay
    Jan 1 at 22:45













  • i now see this issue happened to others but was not answered nor solved at github: github.com/laravel/nova-issues/issues/734

    – David Gabbay
    Jan 1 at 22:47














-1












-1








-1








i"m using laravel+Nova, connecting to existing database of an existing software. The primary key is not the deault "ID" so at the "model" i changed it to like that:



<?php

namespace App;

use IlluminateDatabaseEloquentModel;

class products extends Model
{
//
protected $table = 't_items';
protected $primaryKey = 'item_num';

public $timestamps = false;

}


=============================================================
When changing and updating the satabase (With nova) there is no error.
However when using save (for new or existing row) there is an error:



SQLSTATE[42000]:[Microsoft][ODBC Driver 13 forSQL Server][SQL Server] Error converting data type nvarchar to numeric 9SQL select top 1 * drom [t_items][item_num] = null

"item_num" is defined as:
numeric
primary key
Allo nulls = false
Identity = false
Identity seed = 0
Identity increment = 0
Length = 9
Numeric precision = 10
Numeric scale = 0


What should i add. i think laravel soed not defining the ID when saving and the server needs it










share|improve this question














i"m using laravel+Nova, connecting to existing database of an existing software. The primary key is not the deault "ID" so at the "model" i changed it to like that:



<?php

namespace App;

use IlluminateDatabaseEloquentModel;

class products extends Model
{
//
protected $table = 't_items';
protected $primaryKey = 'item_num';

public $timestamps = false;

}


=============================================================
When changing and updating the satabase (With nova) there is no error.
However when using save (for new or existing row) there is an error:



SQLSTATE[42000]:[Microsoft][ODBC Driver 13 forSQL Server][SQL Server] Error converting data type nvarchar to numeric 9SQL select top 1 * drom [t_items][item_num] = null

"item_num" is defined as:
numeric
primary key
Allo nulls = false
Identity = false
Identity seed = 0
Identity increment = 0
Length = 9
Numeric precision = 10
Numeric scale = 0


What should i add. i think laravel soed not defining the ID when saving and the server needs it







laravel laravel-nova






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 31 '18 at 23:06









David GabbayDavid Gabbay

171




171













  • Hi David, i saw Error converting data type nvarchar to numeric in the error message. could you turn off the auto increments of the primary key using $incrementing = false on the model?

    – Bagus Tesa
    Dec 31 '18 at 23:15











  • i tried it. still get this error: SQLSTATE[42000]:[Microsoft][ODBC Driver 13 for SQL Server][SQL Server] Cannot insert the value NULL into column 'item_num'....

    – David Gabbay
    Jan 1 at 6:26











  • Cannot insert the value NULL into column 'item_num'. hold on David, could you post how you insert the data? after settings $incrementing to false you had always to assign the primary key manually whenever you save new model..

    – Bagus Tesa
    Jan 1 at 7:35











  • nova does not ask for id when create a new row. i dont fined how to make it ask for it. Though i added required to this field at App/Nova/Produccts php like so: public function fields(Request $request) { return [ ID::make('ID', 'item_num') ->creationRules('required') ->sortable(), Text::make('item_name') ]; }

    – David Gabbay
    Jan 1 at 22:45













  • i now see this issue happened to others but was not answered nor solved at github: github.com/laravel/nova-issues/issues/734

    – David Gabbay
    Jan 1 at 22:47



















  • Hi David, i saw Error converting data type nvarchar to numeric in the error message. could you turn off the auto increments of the primary key using $incrementing = false on the model?

    – Bagus Tesa
    Dec 31 '18 at 23:15











  • i tried it. still get this error: SQLSTATE[42000]:[Microsoft][ODBC Driver 13 for SQL Server][SQL Server] Cannot insert the value NULL into column 'item_num'....

    – David Gabbay
    Jan 1 at 6:26











  • Cannot insert the value NULL into column 'item_num'. hold on David, could you post how you insert the data? after settings $incrementing to false you had always to assign the primary key manually whenever you save new model..

    – Bagus Tesa
    Jan 1 at 7:35











  • nova does not ask for id when create a new row. i dont fined how to make it ask for it. Though i added required to this field at App/Nova/Produccts php like so: public function fields(Request $request) { return [ ID::make('ID', 'item_num') ->creationRules('required') ->sortable(), Text::make('item_name') ]; }

    – David Gabbay
    Jan 1 at 22:45













  • i now see this issue happened to others but was not answered nor solved at github: github.com/laravel/nova-issues/issues/734

    – David Gabbay
    Jan 1 at 22:47

















Hi David, i saw Error converting data type nvarchar to numeric in the error message. could you turn off the auto increments of the primary key using $incrementing = false on the model?

– Bagus Tesa
Dec 31 '18 at 23:15





Hi David, i saw Error converting data type nvarchar to numeric in the error message. could you turn off the auto increments of the primary key using $incrementing = false on the model?

– Bagus Tesa
Dec 31 '18 at 23:15













i tried it. still get this error: SQLSTATE[42000]:[Microsoft][ODBC Driver 13 for SQL Server][SQL Server] Cannot insert the value NULL into column 'item_num'....

– David Gabbay
Jan 1 at 6:26





i tried it. still get this error: SQLSTATE[42000]:[Microsoft][ODBC Driver 13 for SQL Server][SQL Server] Cannot insert the value NULL into column 'item_num'....

– David Gabbay
Jan 1 at 6:26













Cannot insert the value NULL into column 'item_num'. hold on David, could you post how you insert the data? after settings $incrementing to false you had always to assign the primary key manually whenever you save new model..

– Bagus Tesa
Jan 1 at 7:35





Cannot insert the value NULL into column 'item_num'. hold on David, could you post how you insert the data? after settings $incrementing to false you had always to assign the primary key manually whenever you save new model..

– Bagus Tesa
Jan 1 at 7:35













nova does not ask for id when create a new row. i dont fined how to make it ask for it. Though i added required to this field at App/Nova/Produccts php like so: public function fields(Request $request) { return [ ID::make('ID', 'item_num') ->creationRules('required') ->sortable(), Text::make('item_name') ]; }

– David Gabbay
Jan 1 at 22:45







nova does not ask for id when create a new row. i dont fined how to make it ask for it. Though i added required to this field at App/Nova/Produccts php like so: public function fields(Request $request) { return [ ID::make('ID', 'item_num') ->creationRules('required') ->sortable(), Text::make('item_name') ]; }

– David Gabbay
Jan 1 at 22:45















i now see this issue happened to others but was not answered nor solved at github: github.com/laravel/nova-issues/issues/734

– David Gabbay
Jan 1 at 22:47





i now see this issue happened to others but was not answered nor solved at github: github.com/laravel/nova-issues/issues/734

– David Gabbay
Jan 1 at 22:47












1 Answer
1






active

oldest

votes


















0














You have to set the column to allow null. This is nothing to do with Laravel. Though it is a pretty strange situation for you not wanting an incrementing id to be set simply as in the "id" column.






share|improve this answer
























  • i dont want to change the defenitions of the database since i"m using an existing database of an existing software.

    – David Gabbay
    Jan 1 at 6:15











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53992039%2flaravel-primary-key-does-not-allow-null%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You have to set the column to allow null. This is nothing to do with Laravel. Though it is a pretty strange situation for you not wanting an incrementing id to be set simply as in the "id" column.






share|improve this answer
























  • i dont want to change the defenitions of the database since i"m using an existing database of an existing software.

    – David Gabbay
    Jan 1 at 6:15
















0














You have to set the column to allow null. This is nothing to do with Laravel. Though it is a pretty strange situation for you not wanting an incrementing id to be set simply as in the "id" column.






share|improve this answer
























  • i dont want to change the defenitions of the database since i"m using an existing database of an existing software.

    – David Gabbay
    Jan 1 at 6:15














0












0








0







You have to set the column to allow null. This is nothing to do with Laravel. Though it is a pretty strange situation for you not wanting an incrementing id to be set simply as in the "id" column.






share|improve this answer













You have to set the column to allow null. This is nothing to do with Laravel. Though it is a pretty strange situation for you not wanting an incrementing id to be set simply as in the "id" column.







share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 31 '18 at 23:37









JohnJohn

215




215













  • i dont want to change the defenitions of the database since i"m using an existing database of an existing software.

    – David Gabbay
    Jan 1 at 6:15



















  • i dont want to change the defenitions of the database since i"m using an existing database of an existing software.

    – David Gabbay
    Jan 1 at 6:15

















i dont want to change the defenitions of the database since i"m using an existing database of an existing software.

– David Gabbay
Jan 1 at 6:15





i dont want to change the defenitions of the database since i"m using an existing database of an existing software.

– David Gabbay
Jan 1 at 6:15




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53992039%2flaravel-primary-key-does-not-allow-null%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas