Why is modelform not saving data to database?

Why is modelform not saving data to database?

For completeness, the UserProfile’s user field is now defined as user = models.OneToOneField (settings.AUTH_USER_MODEL) and the User.profile lambda expression is unchanged. I’m not sure exactly what the problem is here, but one issue certainly is that you are passing instance=request.user when instantiating the form.

Why is edit after comments not saving data?

Edit after comments The problem now is that you’re instantiating the form with the first parameter, data, even when the request is not a POST and therefore request.POST is an empty dictionary. But the data parameter, even if it’s empty, takes precedence over whatever is passed as initial data.

How to edit and save data back to database?

As a best practice to prevent overposting, the fields that you want to be updateable by the Edit page are whitelisted in the TryUpdateModel parameters. To make the above work for DoctorViewModel, the second parameter (prefix) needs to be used too.

How to use a custom model binder in EF Core?

The AuthorEntityBinder requires DI to access EF Core. Use BinderTypeModelBinder if your model binder requires services from DI. To use a custom model binder provider, add it in ConfigureServices: When evaluating model binders, the collection of providers is examined in order.

Why is the Entity Framework not saving changes?

I’ve got an MVC web application that uses SQL Server 2008 as a back end database along with the Entity Framework. The application is working fine and pulling data from the database just fine. My problem is, when it does an update to the data, it doesn’t appear to be saving it.

How to save modelform to database in Django?

Register your models here. db_obj should be an object of table UserProfile that you want to save. I think you need to 1st create an object for ModelForm and then assign the object on if the request method is post. In your code you are only doing this for only one attribute and before checking the method.

What does it mean when dbcontext is not saving?

That means you are basically calling save changes on a brand new instance of DbContext that has absolutely no changes. You should always add and attach your entities to the same instance of DbContext that you then call save changes on.