Web API 2 cannot register user

I have a Web API 2 project using MVC. It uses entity infrastructure. This entity structure uses the first database approach with the .edmx file.

The project is based on the VS 2013 Express Web API 2 template. I just used my own database. I did not change the code associated with the account. But when I try to register a new user, the following statement in AccountController.cs throws an exception:

public async Task<IHttpActionResult> Register(RegisterBindingModel model) { ... IdentityResult result = await UserManager.CreateAsync(user, model.Password); ... } 

An exception:

 Cannot insert the value NULL into column 'Discriminator', table 'xxx.dbo.AspNetUsers'; column does not allow nulls. INSERT fails. The statement has been terminated. 

Can anyone help me? Thanks!

+1
source share
2 answers

Yesterday I updated all the NuGet packages. Among them, Asp.net Identity is updated to 2.0.0.0.

It worked magically.

Therefore, I suspect that this was due to an error in Identity 1.0

0
source

The answer is in your body of the question.

table 'xxx.dbo.AspNetUsers'; column does not allow nulls.

It seems you are trying to insert a NULL value from an instance of the RegisterBindingModel model , where the structure of your table on the database server does not allow to accept a NULL value.

Try debugging and checking if your model is instantiated correctly when the request arrives.

Also I see that you are using:

 IdentityResult result = await UserManager.CreateAsync(user, model.Password); 

Why is the user not a member of your model, for example, the Password property? Perhaps try using:

 IdentityResult result = await UserManager.CreateAsync(model.User, model.Password); 

In any case ... I no longer have information and can not imagine what is inside the model instance, how do you bind data to it from the request. You should look in the debugger and debug very well to restore the project or provide additional information.

But one thing is clear, like a crystal, you are trying to insert a NULL value in a column that does not accept NULL , so you should check how your model binds. Perhaps your client application is sending some arguments incorrectly, maybe you are not binding the model correctly, maybe something else ... You need to get more information from you to help you, otherwise you must carefully debug it.

0
source

Source: https://habr.com/ru/post/979582/


All Articles