Answer the question
In order to leave comments, you need to log in
Why doesn't autoincrement work when creating a record in MS SQL database?
When adding a second category (the first one was added normally) , it swears that there is already a value with the same id
.
visual studio 2010, MVC3, entity framework, SQL Manager lite, code generated by CRUD Categories
table:
[Id] int IDENTITY(1, 1) NOT NULL,
[ParentId] int NOT NULL,
[Title] nchar(255) NOT NULL,
CONSTRAINT [categories] PRIMARY KEY NONCLUSTERED ([Id])
WITH (
PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON
)
Answer the question
In order to leave comments, you need to log in
I figured it out, the point was that I needed to declare the data that I want to write to the database through the model.
If you don’t declare it, an empty id field is sent from the page for adding a category, which is equal to 0 (since the id in the database is not null) and is already present in Thank
you all, issue resolved
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question