Open amikable-tech opened 1 year ago
hi guys when i created the class AcademicExperience, i ran python3 manage.py makemigrations and i got this error
Please what do i do in this situation. or should have i run a different command instead
@JoeyStk & @to-sta
@amikable-tech this prompt is raised because there is a database with data and migrations in the project. Like the message stats:
It is impossible to add a non-nullable field 'user' to personalinformation without specifying a default. This is because the database needs somthing to populate existing rows.
There are mulitple ways of dealing with this:
Setting the null keyword argument for the user field to True or default=None. But these are both just hotfixes. Since we have the db.sqllite3
and the __pycache__/
files in the gitignore, i will delete these files and make another commit. I will also add migrations to the .gitignore file for now @JoeyStk since we are not in production there is no need to keep migrations yet.
class PersonalInformation(models.Model):
name = models.CharField(max_length=25, blank=False)
user = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
...
class PersonalInformation(models.Model):
name = models.CharField(max_length=25, blank=False)
user = models.ForeignKey(User, on_delete=models.CASCADE, default=None)
...
Then it should work well 😃. You should copy your changes and then pull the latest version.
Now there is no db.sqllite3
inside the repo as well as migration files (0001_ intial.py
,...) and __pycache__
. You might have to delete your db.sqllite3
before you make migrations again.
Requirements