Laravel primary key does not allow null
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
|
show 1 more comment
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
Hi David, i sawError 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
tofalse
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
|
show 1 more comment
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
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
laravel laravel-nova
asked Dec 31 '18 at 23:06
David GabbayDavid Gabbay
171
171
Hi David, i sawError 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
tofalse
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
|
show 1 more comment
Hi David, i sawError 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
tofalse
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
|
show 1 more comment
1 Answer
1
active
oldest
votes
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.
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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
tofalse
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