Reputation: 1
I'm new to Django development and I'm currently following a tutorial to make a blog app. During the tutorial, there is a step to create a function to allow new user use deafult.jpg
as their avatar.
However, I had a typo there. Instead of typing 'default.jpg'
, I typed 'default.jpb'
.
Then I migrated into the database. Therefore, when I run the server and try it out, new users who have not set their avatar is using "default.jpb"
instead of "default.jpg"
.
Now, how can I change the database to use the right definition?
After I found the problem, I corrected my typo in my model and then used the following command:
python3 manage.py makemigrations (no changes detected)
python3 manage.py migrate (no migrations to apply)
then, I decided to delete the migrations in my project then makemigrations again, and I realized that I couldn't make changes that already inside my database.
from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
image = models.ImageField(default='default.jpg', upload_to='profile_pics')
def __str__(self):
return f'{self.user.username} Profile'
I expect new users who have not set their avatar is using default.jpg that located in my project.
Upvotes: 0
Views: 423
Reputation: 61
run python3 manage.py makemigrations profile and then run python3 manage.py migrate this will solve the issue
Upvotes: 0
Reputation: 5793
The problem is you deleted the migrations files. This means when you run makemigrations
again it will have name it as 001...
. BUT the database will still have a record of migrating that file in django_migrations
.
Either undelete the deleted migrations and run makemigrations then migrate OR edit your database and remove the migrations that you've deleted from django_migrations
Upvotes: 1