c# - Getting error for EF code first migration- Column 'AspNetUsers.Id' is not the same length or scale as referencing column -
when trying generate tables using migration getting following exception-
column 'aspnetusers.id' not same length or scale referencing column 'mycustomtable.userid' in foreign key 'fk_mycustomtable_aspnetusers_userid'. columns participating in foreign key relationship must defined same length , scale. not create constraint or index.
this code-
public class applicationuser : identityuser { public string firstname { get; set; } public string lastname { get; set; } public string customerid { get; set; } public string address { get; set; } public string description { get; set; } public string parentuserid { get; set; } ... }
this migration class-
public partial class createidentityschema : migration { protected override void up(migrationbuilder migrationbuilder) { migrationbuilder.createtable( name: "aspnetusers", columns: table => new { id = table.column<string>(nullable: false), accessfailedcount = table.column<int>(nullable: false), concurrencystamp = table.column<string>(nullable: true), email = table.column<string>(maxlength: 256, nullable: true), emailconfirmed = table.column<bool>(nullable: false), lockoutenabled = table.column<bool>(nullable: false), lockoutend = table.column<datetimeoffset>(nullable: true), ... }, constraints: table => { table.primarykey("pk_aspnetusers", x => x.id); }); migrationbuilder.createtable( name: "mycustomtable", columns: table => new { id = table.column<int>(nullable: false) .annotation("sqlserver:valuegenerationstrategy", sqlservervaluegenerationstrategy.identitycolumn), userid = table.column<string>(nullable: true), ... }, constraints: table => { table.primarykey("pk_mycustomtable_id", x => new { x.id }); table.foreignkey( name: "fk_mycustomtable_aspnetusers_userid", column: x => x.userid, principaltable: "aspnetusers", principalcolumn: "id", ondelete: referentialaction.cascade); }); } }
and modelsnapshot-
[dbcontext(typeof(applicationdbcontext))] partial class applicationdbcontextmodelsnapshot : modelsnapshot { protected override void buildmodel(modelbuilder modelbuilder) { modelbuilder.entity("datamodel.dbmodels.applicationuser", b => { b.property<string>("id"); b.property<int>("accessfailedcount"); b.property<string>("concurrencystamp") .isconcurrencytoken(); b.property<string>("email") .hasannotation("maxlength", 256); b.property<bool>("emailconfirmed"); b.property<bool>("lockoutenabled"); b.property<datetimeoffset?>("lockoutend"); ... b.totable("aspnetusers"); }); modelbuilder.entity<datamodel.entities.mycustomtable>(b => { b.property<int>("id") .hasannotation("sqlserver:valuegenerationstrategy", sqlservervaluegenerationstrategy.identitycolumn); b.property<string>("userid"); ... b.haskey("id"); b.totable("mycustomtable"); }); modelbuilder.entity<datamodel.entities.mycustomtable>(b => { b.hasone("datamodel.dbmodels.applicationuser") .withmany("mycustomtable") .hasforeignkey("userid") .ondelete(deletebehavior.cascade); }); } }
i don't doing wrong. if 1 can helpful me. thanks.
Comments
Post a Comment