Problems with updating the database using code first migrations

Source: Internet
Author: User

Error message: the 'title' Column cannot be inserted with a null value. Table 'mvccorperation. Models. corperationdbcontext. DBO. Articles '; the column cannot have a null value. Update failed.

The statement has been terminated.

Environment: A database table already exists. The database table also has data. I just added dataannotations to the model, and then used the add-migration and update-database commands to prompt the above error.

Cause of error: the original database contains data records that do not meet the new constraints. The title field of a record is null, and the new condition is that the title field cannot be null.

Solution: Before executing Update-database, make sure that the data records in the database meet the new constraints. If any, an error is returned. I deleted the data and re-executed the update-database operation.

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.