Holy Cow - after many hours of trying, I finally figured it out.
First I make an EF6 database, and I was interested in learning about the error "unknown column length" - for some reason, it called the column name of the column name of the column name of the underscore table and tried to find a nonexistent column.
In my case, one of my tables had two foreign key references to the same primary key in another table - something like this:
Animals Owners
EF generated some weird column name, like Owners_AnimalID1 and Owners_AnimalID2 , and then kept breaking.
The trick is that these confusing foreign keys must be registered with EF using the Fluent API!
In the context of the main database, override the OnModelCreating method and modify the configuration of the object. Preferably, you will have a separate file that extends the EntityConfiguration class, but you can do it inline.
In any case, you should add something like this:
public class OwnerConfiguration : EntityTypeConfiguration<Owner> { public OwnerConfiguration() { HasRequired(x => x.Animals) .WithMany(x => x.Owners)
And with that, EF (maybe) will start to work as you expect. Boom.
In addition, you will get the same error if you use the .HasOptional() columns above - just use .HasOptional() instead of .HasRequired() .
Here is the link that placed me over the hump:
https://social.msdn.microsoft.com/Forums/en-US/862abdae-b63f-45f5-8a6c-0bdd6eeabfdb/getting-sqlexception-invalid-column-name-userid-from-ef4-codeonly?forum=adonetefx
And then, the Fluent APIs help, especially the foreign key examples:
http://msdn.microsoft.com/en-us/data/jj591620.aspx
You can also place configurations on the other end of the key, as described here:
http://www.entityframeworktutorial.net/code-first/configure-one-to-many-relationship-in-code-first.aspx .
There are some new issues that I am facing right now, but it was a huge conceptual gap that was missing. Hope this helps!