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.
This commit is contained in:
Corban-Lee Jones 2024-01-20 19:50:20 +00:00
parent c9e59c5c66
commit 5957ddf8f1
3 changed files with 3 additions and 7 deletions

View File

@ -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",

View File

@ -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')),

View File

@ -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(