Answer the question
In order to leave comments, you need to log in
How to correctly add a User to an existing model?
How to correctly add a connection with the User to the existing model, so that the default author is already affixed to the previously created records, and the current one who creates the material is indicated on the new ones. I create
a field in the model - where I specify the default id of the user - but he uses it on new ones author = models.ForeignKey
(User, on_delete=models.CASCADE, default=2)
if you write without default
author = models.ForeignKey(User, on_delete=models.CASCADE)
then the error will be
NOT NULL constraint failed: project.author_id Tell me
how right to do?
Answer the question
In order to leave comments, you need to log in
Or manually edit the migration
Or, when creating new authors, override in the code
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question