1
votes

having trouble with Seeding data in Package manager.

Getting an error: Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.

Question:

1) Why would it ever do on Fresh new database (I had this solution connected to a bit older database, but I runned into exact same issue, therefore tryed creating DB from scratch, and got the same issue again).

2) As far as I can see EntityValidationErrors is a varialbe. But I am running PM>Database-Update -verbose method, it does not use any runtime?

I mean I would love to see it/debug it/but where, how should, can I see it? How can you see this variable if there is no Runtime involved? Am getting error in Package manager.

1

1 Answers

1
votes

Well apparently

1) My Id property of model class was String (accidentaly).

2) This prevented "Auto_increment" from being set on that column.

3) Since in Seed() method, I was relying on autoincrement - that is why it was throwing validation error.

Solution was to add

[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ID { get; set; }

Then delete old migration file ([Something]Migration.cs) from Migrations folder.

Then Drop table/recreate table or if needed drop/recreate database.

After all is done, be sure to enable migrations again, and add a new migration.

After that, run seed method again. This worked just fine.