You cannot insert a value of NULL into the column ' ID ', table ' EupStoreDemoDB.dbo.OrderDiary ', and the column does not allow null values. INSERT failed.

Source: Internet
Author: User

MVC, using EF to build entities. The data is stored in the database and executed to _db. SaveChange (), the following error is reported:

In the database data storage, often encounter this problem, the cause of this error is a variety of Internet search solutions, as follows:

1. There is said to set the null option to "can be empty", but I This "ID" field is the primary key, how can be set to be empty? Veto

2. Say that the identity specification is set to "yes", such as, however, that the identity specification is selected as "Yes" is to add the self-increment function to the field, which should require that the field type is integer? My field type is "Guid" and cannot modify the identity specification to "yes", so the second solution can't solve my problem, veto

On the internet basically these two solutions, can not solve the problem, eh, still have to find their own slowly, finally:

Workaround:

First step: Open the. edmx file, select the field that is faulted, and in the property box on the right, set StoreGeneratedPattern to "None", such as:

Step Two: Right-click the table view in the. edmx file, select Generate database from model, as follows

Step Three: Fool operation, no tube, direct point "complete" is "yes"

Fourth step: Run the program, problem solving, haha!

You cannot insert a value of NULL into the column ' ID ', table ' EupStoreDemoDB.dbo.OrderDiary ', and the column does not allow null values. INSERT failed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.