Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autogenerate ID GUID datatype Entity Framework

I have looked at this post and tried to do it this way

Autogenerate primary key (Guid) Entity Framework CTP5

 [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
 public Guid CompanyID { set; get; }

However I am still getting the error

Identity column 'CompanyID' must be of data type int, bigint, smallint, tinyint, or decimal or numeric with a scale of 0, and constrained to be nonnullable.

This is when I run Update-Database command on the package manager console.

like image 774
Johnathon64 Avatar asked Oct 20 '22 06:10

Johnathon64


1 Answers

Had the same issue, the only thing helped me is dropping database to initial empty state, removing all migrations and creating a new one with proper GUID key:

  1. Update-Database -TargetMigration:0
  2. Remove all migrations
  3. Add-Migration InitialCreate
  4. Update-Database

I agree that this is not a best solution, but it was acceptable for me since I had started project a few hours before.

like image 168
Vsevolod Krasnov Avatar answered Oct 29 '22 21:10

Vsevolod Krasnov