Entity Framework Migrations Error - Sequence contains no elements

What was causing the issue for me was changing the name together with changing the relations associated with the entity.

So my resolution in my case was:

  • Changing the name back to the old one
  • Adding the migration (then was able to do it)
  • Updating the database
  • Changing the name of the entity and generating a new migration

There can be potentially many other causes of this issue, though - e.g. removing the migration after it was applied. Unfortunately, in none of them this error is meaningful.


This problem occurs to me when a try to define type and size of a column with DataAnnotations.

BAD:

[Column(TypeName="VARCHAR(254)")]
public string ColumnName { get; set; }

OK:

[MaxLength(254)]
[Column(TypeName="VARCHAR")]
public string ColumnName { get; set; }