How to add User to an existing model?

How to add in the existing model of communication with the User, that would be on a previously created record has been marked already the author by default, and the new indicated current who creates the material

Create a field in the model - where you put in the default user id - but he and the new uses it also
author = models.ForeignKey(User, on_delete=models.CASCADE, default=2)

if to write without default
author = models.ForeignKey(User, on_delete=models.CASCADE)
the error vyletaet
NOT NULL constraint failed: project.author_id

Tell me how to do?
April 3rd 20 at 17:28
2 answers
April 3rd 20 at 17:30
Solution
Or manually edit the migration
Or when creating a new author to override in your code
Tell me how to override?
I understand
self.autor = but what is there to write I do not understand - johnnie.Runolfsdott commented on April 3rd 20 at 17:33
Leave the default value, simply by creating a new object priobretesh author on up-to-date view function - keely_Jaskolski commented on April 3rd 20 at 17:36
I create an object from the admin - view function is not there
it can is possible to override in the model
def save(self, *args, **kwargs):
self.autor = but what is there to write I do not understand
super().save(*args, **kwargs) - johnnie.Runolfsdott commented on April 3rd 20 at 17:39
If you create only from the admin area, then so
https://docs.djangoproject.com/en/dev/ref/contrib/... - keely_Jaskolski commented on April 3rd 20 at 17:42
@keely_Jaskolski,
Pls reply - johnnie.Runolfsdott commented on April 3rd 20 at 17:45
April 3rd 20 at 17:32
he new uses it also


So when you save, you don't specify what User should be used.
how is it possible to specify? can't find how to do that - johnnie.Runolfsdott commented on April 3rd 20 at 17:35

Find more questions by tags Django