Answer the question
In order to leave comments, you need to log in
I can't make a migration, how to solve it?
When I write python manage.py makemigrations it gives me
You are trying to add a non-nullable field 'author' to review without a default; we can't do that (the d
atabase needs something to populate existing rows).
Please select a fix:
1) Provide a one-off default now (will be set on all existing rows with a null value for this column)
2) Quit, and let me add a default in models.py
Select an option:
class Review(models.Model):
author = models.CharField(max_length=100)
text = models.CharField(max_length=100)
movie = models.ForeignKey(Movie, on_delete=models.CASCADE)
def __str__(self):
return self.author
Answer the question
In order to leave comments, you need to log in
Well, do you even understand what he wants from you?
You add a field to the table. So, you need to decide what value this new field will take in existing rows .
By default, with this addition, already existing rows in the table will receive NULL in these fields. But you indicated that the field cannot be NULL.
Then the default value should be used. But you didn't specify a default value in the model description.
And the script offers you two options.
1. Enter a value that the script will substitute here and now into existing rows in the database instead of NULL. The model will not be changed.
2. Manually set the default value in the model and restart the script. It uses this default value for existing rows instead of NULL.
Decide for yourself which is better.
You added a field, the field cannot be NULL. But there may already be records in the database that apparently did not contain this field (because you just added it). This means that all existing records need to put something in this field.
Although it was enough to translate the text, the same thing is written there.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question