Реализую пользовательскую модель, как написано в документации, но возникает ошибка OperationalError.
Мой код:
class HandField(models.Field):
description = "A hand of cards (bridge style)"
def __init__(self, *args, **kwargs):
kwargs['max_length'] = 104
super().__init__(*args, **kwargs)
def deconstruct(self):
name, path, args, kwargs = super().deconstruct()
del kwargs["max_length"]
return name, path, args, kwargs
class FinishModel(models.Model):
root = HandField()
@admin.register(FinishModel)
class FinishModelAdmin(admin.ModelAdmin):
list_display = ('root',)
Текст ошибки:
OperationalError at /admin/element_one/finishmodel/add/
table element_one_finishmodel has no column named root
Request Method: POST
Request URL: http://127.0.0.1:8000/admin/element_one/finishmodel/add/
Django Version: 4.1.3
Exception Type: OperationalError
Exception Value:
table element_one_finishmodel has no column named root
Exception Location: /home/ioann/.local/share/virtualenvs/TREANING_FOR_DJANGO-qmgCEbuO/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py, line 357, in execute
Raised during: django.contrib.admin.options.add_view
Python Executable: /home/ioann/.local/share/virtualenvs/TREANING_FOR_DJANGO-qmgCEbuO/bin/python
Python Version: 3.8.10
Python Path:
['/home/ioann/pythonProject/pythonProject/TREANING_FOR_DJANGO/base_part',
'/usr/lib/python38.zip',
'/usr/lib/python3.8',
'/usr/lib/python3.8/lib-dynload',
'/home/ioann/.local/share/virtualenvs/TREANING_FOR_DJANGO-qmgCEbuO/lib/python3.8/site-packages']
Server time: Tue, 08 Nov 2022 15:49:55 +0000
Миграции есть
class Migration(migrations.Migration):
dependencies = [
('element_one', '0017_remove_finishmodel_root'),
]
operations = [
migrations.AddField(
model_name='finishmodel',
name='root',
field=element_one.models.HandField(default=1),
preserve_default=False,
),
]
В PyCharm ошибка:
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such column: element_one_finishmodel.root