简体   繁体   中英

Cannot define PRIMARY KEY constraint on colum Entity frame Code first

how to solve this error in migration i am using old developer code i don't know how do this i spend 3 4 hours in this but not solve please any one help me

Cannot define PRIMARY KEY constraint on column 'vOid' in table 'table1'. The computed column has to be persisted and not nullable. Could not create constraint or index. See previous errors

       public Guid VOid { get; set; }

 entity.HasKey(e => e.VOid)
                    .ForSqlServerIsClustered(false);

         entity.Property(e => e.VOid)
                            .HasColumnName("vOid")
                            .HasComputedColumnSql("(CONVERT([uniqueidentifier],json_value([value],'$._id'),(0)))")
                            .ValueGeneratedNever();

Would be helpful to see the table structure you are referring to, but I assume, as the error says, that the column should be "not nullable". You could give this a try:

ALTER TABLE table1
ALTER COLUMN vOid INT NOT NULL
GO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM