Я пытаюсь добавить дополнительные поля для модели User. Команды migrate и makemigrations работали. Когда я пытаюсь создать createuperuser, эта ошибка возникает. Postgresql включен. Я пытался изменить upload_to, добавить «blank = True», «default» к параметрам модели, но ничего не изменилось.
Трассировка:
return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedTable: ОШИБКА: отношение "blog_customuser" не существует
LINE 1: ..._customuser"."age", "blog_customuser"."city" FROM "blog_cust...
^
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\Роман\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\Роман\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Роман\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Роман\AppData\Local\Programs\Python\Python37\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 61, in execute
return super().execute(*args, **options)
File "C:\Users\Роман\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\base.py", line 364, in execute
output = self.handle(*args, **options)
File "C:\Users\Роман\AppData\Local\Programs\Python\Python37\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 95, in handle
error_msg = self._validate_username(username, verbose_field_name, database)
File "C:\Users\Роман\AppData\Local\Programs\Python\Python37\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 201, in _validate_username
self.UserModel._default_manager.db_manager(database).get_by_natural_key(username)
File "C:\Users\Роман\AppData\Local\Programs\Python\Python37\lib\site-packages\django\contrib\auth\base_user.py", line 44, in get_by_natural_key
return self.get(**{self.model.USERNAME_FIELD: username})
File "C:\Users\Роман\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\Роман\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\query.py", line 402, in get
num = len(clone)
File "C:\Users\Роман\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\query.py", line 256, in __len__
self._fetch_all()
File "C:\Users\Роман\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\query.py", line 1242, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "C:\Users\Роман\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\query.py", line 55, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "C:\Users\Роман\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\sql\compiler.py", line 1097, in execute_sql
cursor.execute(sql, params)
File "C:\Users\Роман\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\utils.py", line 99, in execute
return super().execute(sql, params)
File "C:\Users\Роман\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\utils.py", line 67, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "C:\Users\Роман\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\utils.py", line 76, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Users\Роман\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\Роман\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\Роман\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: ОШИБКА: отношение "blog_customuser" не существует
LINE 1: ..._customuser"."age", "blog_customuser"."city" FROM "blog_cust...
Модель:
from django.db import models
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
avatar = models.ImageField(upload_to='images/%Y/%m/%d', blank=True, max_length=1000)
age = models.CharField(blank=True,max_length=200)
class Post(models.Model):
title = models.CharField(max_length=100,blank=True,db_index=True)
body = models.TextField(max_length=500,blank=True,db_index=True)
date_pub = models.DateTimeField(auto_now_add=True)
author = models.ForeignKey(User, related_name='posts',on_delete=models.PROTECT)