This article is a mirror article of machine translation, please click here to jump to the original article.

View: 23561|Reply: 0

[Source] Entity Framework adds unique constraints

[Copy link]
Posted on 6/25/2018 2:53:31 PM | | |
When a unique constraint is added before a field, the following error is reported:

EntityFramework: Column ‘COLUMN_NAME’ in table ‘dbo.TABLE_NAME’ is of a type that is invalid for use as a key column in an index


Error Message:
Column 'MacAddress' in table 'dbo. AspNetUsers' is of a type that is invalid for use as a key column in an index.


Reason of the problem
This error is because the unique constraint can’t be over 8000 bytes per row and will only use the first 900 bytes even then so the safest maximum size for my field would be 450 characters.


Solution to the problem
To add this limitation in code first model just add the [MaxLength(450)] attribute to your property as shown in the code below.






Previous:Newcomers register, please pay attention
Next:High-energy warning! Be wary of EnMiner mining
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com