Hi,
I successfully managed to increase the UserName field length based on advice from a previous post, as follows:
public class User : AbpUser<User>
{
...
[StringLength(256)]
public override string UserName { get; set; }
...
}
However, since upgrading to ABP v3.5, I am unable to migrate my database. This seems to be due to the fact that UserAccount.UserLength now has a maximum length of 32 and the migration would cause its contents to truncate.
How can I increase the MaxLength of UserAccount.UserName ? I have tried creating a custom UserAccount class and overriding UserName with the required MaxLength, but this does not work.
11 Answer(s)
-
0
Hi,
You can check <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/3460#issuecomment-394612406">https://github.com/aspnetboilerplate/as ... -394612406</a>.
-
0
Hi,
That got me some of the way there...
I added the following to dBContext..
modelBuilder.Entity<User>().Property(u => u.UserName).HasMaxLength(256); modelBuilder.Entity<UserAccount>().Property(u => u.UserName).HasMaxLength(256);
I then performed a migration. This succeeded, and User.UserName and UserAccount.UserName are now set at nvarchar(256)
However, attempting to create a user, I get an Internal Server Error, with the following message in the log file:
ERROR 2018-06-07 15:11:48,617 [10 ] loud.EntityFramework.IppexCloudDbContext - There are some validation errors while saving changes in EntityFramework: ERROR 2018-06-07 15:11:48,617 [10 ] loud.EntityFramework.IppexCloudDbContext - - UserName: The field UserName must be a string with a maximum length of 32.
So, something is still holding on to the 32 character limit.
I am using AspNetZero v4 MVC with Abp v3.5
-
0
@PhilWynn sorry, I forgot to mention. You also need to change the related DTO classes. They probably have MaxLenght attribute on Username fields.
-
0
Hi,
I already did this. I have had the long UserName working for some time now on a previous version of ABP.
The error I am getting is since updating to v3.5 ABP and comes from Entity Framework (see log text in previous post)
Cheers
-
0
Any more thoughts on this please...
-
0
hi,
to increase username length you set the AbpUserBase.MaxUserNameLength before base.OnModelCreating(modelBuilder); If you do this you don't need to change DTOs. remove all migrations before you do this
protected override void OnModelCreating(ModelBuilder modelBuilder) { AbpUserBase.MaxUserNameLength = 999; base.OnModelCreating(modelBuilder); //... }
-
0
Hi,
AbpUserBase.MaxUserNameLength is a constant. I cannot change this...
-
0
Yeah you are right. I wish they were static not const. So you are still getting the Entity Framework exception ( UserName: The field UserName must be a string with a maximum length of 32.) ?
You might have forgotten to change the related CSHTML files that's used for validation but this will not cause the Entity Framework exception. Check your database table whether the migration is successfully applied or not.
-
0
One more thing;
You also need to increase the length of 'NormalizedUserName' field of User entity and 'UserName' field of UserAccount entity.
See <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/3460">https://github.com/aspnetboilerplate/as ... ssues/3460</a>
-
0
Hi,
Yes, I can confirm that the database has been migrated successfully.
NormalizedUserName does not exist in the MVC version.
Looks like an issue has now been created to increase the max length of UserName:
<a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/3502">https://github.com/aspnetboilerplate/as ... ssues/3502</a>
-
0
ok. so let's track the issue.