From 5957ddf8f1e23a1d4630f89a6f8bd8725838cf09 Mon Sep 17 00:00:00 2001 From: corbz Date: Sat, 20 Jan 2024 19:50:20 +0000 Subject: [PATCH] Fixed Issue Making Django Suggest `makemigrations` Was using BASE_DIR in the default image path for the authentication.User model. This is a problem because BASE_DIR may change with the host machine, which it did in my case. Django sees the changed path and incorrectly recommends making migrations again. --- apps/authentication/fixtures/defaultuser.json | 3 --- apps/authentication/migrations/0001_initial.py | 5 ++--- apps/authentication/models.py | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/apps/authentication/fixtures/defaultuser.json b/apps/authentication/fixtures/defaultuser.json index 02e0d88..a2cd7db 100644 --- a/apps/authentication/fixtures/defaultuser.json +++ b/apps/authentication/fixtures/defaultuser.json @@ -205,7 +205,6 @@ "fields": { "password": "pbkdf2_sha256$260000$h4zLYmIeMQgJ0ko41i6dxo$Gwe0TV75ibdJTtqdTOOs5ucOEhA9DUM/bwxjagVhKKg=", "last_login": "2024-01-13T20:53:38.159Z", - "icon": "../static/images/defaultuser.webp", "email": "admin@mail.com", "forename": "Default", "surname": "Admin User", @@ -385,7 +384,6 @@ "fields": { "password": "pbkdf2_sha256$260000$h4zLYmIeMQgJ0ko41i6dxo$Gwe0TV75ibdJTtqdTOOs5ucOEhA9DUM/bwxjagVhKKg=", "last_login": "2024-01-13T19:58:12Z", - "icon": "../static/images/defaultuser.webp", "email": "ricky.simmmons@example.com", "forename": "Ricky", "surname": "Simmmons", @@ -545,7 +543,6 @@ "fields": { "password": "pbkdf2_sha256$260000$h4zLYmIeMQgJ0ko41i6dxo$Gwe0TV75ibdJTtqdTOOs5ucOEhA9DUM/bwxjagVhKKg=", "last_login": null, - "icon": "../static/images/defaultuser.webp", "email": "dora.hudson@example.com", "forename": "Dora", "surname": "Hudson", diff --git a/apps/authentication/migrations/0001_initial.py b/apps/authentication/migrations/0001_initial.py index fe0afa6..5318556 100644 --- a/apps/authentication/migrations/0001_initial.py +++ b/apps/authentication/migrations/0001_initial.py @@ -1,10 +1,9 @@ -# Generated by Django 3.2.16 on 2024-01-19 09:34 +# Generated by Django 3.2.16 on 2024-01-20 19:15 import apps.authentication.models from django.db import migrations, models import django.db.models.deletion import django.utils.timezone -import pathlib import uuid @@ -31,7 +30,7 @@ class Migration(migrations.Migration): ('password', models.CharField(max_length=128, verbose_name='password')), ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), - ('icon', models.ImageField(default=pathlib.PurePosixPath('/mnt/code/ticket-website/static/images/defaultuser.webp'), storage=apps.authentication.models.OverwriteStorage(), upload_to=apps.authentication.models.IconPathGenerator(), verbose_name='profile picture')), + ('icon', models.ImageField(default='../static/images/defaultuser.webp', storage=apps.authentication.models.OverwriteStorage(), upload_to=apps.authentication.models.IconPathGenerator(), verbose_name='profile picture')), ('email', models.EmailField(error_messages={'unique': 'A user with this email address already exists.'}, max_length=254, unique=True, verbose_name='email address')), ('forename', models.CharField(help_text='This should be your real first name.', max_length=150, verbose_name='first name')), ('surname', models.CharField(help_text='This should be your real last name.', max_length=150, verbose_name='last name')), diff --git a/apps/authentication/models.py b/apps/authentication/models.py index 3766e90..5447fe4 100644 --- a/apps/authentication/models.py +++ b/apps/authentication/models.py @@ -70,7 +70,7 @@ class User(AbstractBaseUser, PermissionsMixin): icon = models.ImageField( _("profile picture"), upload_to=IconPathGenerator(), - default=settings.BASE_DIR / "static/images/defaultuser.webp", + default="../static/images/defaultuser.webp", # Path starts from media dir storage=OverwriteStorage() ) email = models.EmailField(