Tras crear aplicacion Users y crear modelo importando AbstractBaseUser. Al hacer makemigrations me devuelve un error. No se si puede ser que el modelo Post tiene una columna llamada author que utiliza 'auth.User' y de alguna manera se haya cambiado su ruta con Users.
ERROR:
ERRORS:
blog.Post.author: (fields.E301) Field defines a relation with the model 'auth.User', which has been swapped out.
HINT: Update the relation to point at 'settings.AUTH_USER_MODEL'.
Archivo models.py
from django.db import models
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
class User(AbstractBaseUser, PermissionsMixin):
username = models.CharField(max_length=10, unique=True)
email = models.FileField()
name = models.CharField(max_length=30)
last_name1 = models.CharField(max_length=30)
USERNAME_FIELD = 'username'
def get_short_name(self):
return self.username
def get_full_name(self):
return self.nombre + '' + self.apellido1 + '' + self.apellido2
Archivo settings.base.py
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog.apps.BlogConfig',
'users',
#...
AUTH_USER_MODEL = 'users.User'
Archivo blog.py
from django.db import models
from django.utils import timezone
class Post(models.Model):
author = models.ForeignKey('auth.User', on_delete=models.CASCADE)
title = models.CharField(max_length=200)
text = models.TextField()
created_date = models.DateTimeField(
default=timezone.now)
published_date = models.DateTimeField(
blank=True, null=True)
def publish(self):
self.published_date = timezone.now()
self.save()
def __str__(self):
return self.title