c# - EF Code First "String or binary would be truncated" when running Update-Database -


my migration looks this:

    public override void up()     {         addcolumn("dbo.targettable", "table1id", c => c.int(nullable: false));         addforeignkey("dbo.targettable", "table1id", "dbo.table1", "id");          addcolumn("dbo.targettable", "table2id", c => c.int(nullable: false));         addforeignkey("dbo.targettable", "table2id", "dbo.table2", "id");     }      public override void down()     {         dropforeignkey("dbo.targettable", "table1id", "dbo.table1", "id");         dropcolumn("dbo.targettable", "table1id", c => c.int(nullable: false));          dropforeignkey("dbo.targettable", "table2id", "dbo.table2", "id");         dropcolumn("dbo.targettable", "table2id", c => c.int(nullable: false));      } 

and when run "update-database" i'm getting error: string or binary data truncated. statement has been terminated.

i'm not creating tables, adding 2 columns existing table. unsure error coming from. i'm not manipulating string or binary columns. appreciated.

edit

the table empty. has no rows, that's why columns fine being non-nullable.

the model:

 public class targettable {     //this column exists.     [databasegenerated(databasegeneratedoption.identity)]     public int id { get; set; }      public int table1id { get; set; }     public virtual table1 table1 { get; set; }      public int table2id { get; set; }     public virtual table2 table2 { get; set; } } 

you inserting not nullable fields existing table. if table contains rows, cause error.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -