LookupError: App 'Hierarchy' doesn't have a 'CustomUser' model - python

I've been following the Django documentation to create a custom user model.
Here is the main error -
(Edit - I was asked to add the entire traceback so here it is)
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django\apps\config.py", line 178, in get_model
return self.models[model_name.lower()]
KeyError: 'customuser'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django\contrib\auth\__init__.py", line 156, in get_user_model
return django_apps.get_model(settings.AUTH_USER_MODEL, require_ready=False)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django\apps\registry.py", line 210, in get_model
return app_config.get_model(model_name, require_ready=require_ready)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django\apps\config.py", line 181, in get_model
"App '%s' doesn't have a '%s' model." % (self.label, model_name))
LookupError: App 'Hierarchy' doesn't have a 'CustomUser' model.
To make matters worse after that is shows the below error, I've done everything that the site told me to, couldn't find the answer anywhere
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\threading.py", line 926, in _bootstrap_inner
self.run()
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\autoreload.py", line 76, in raise_last_exception
raise _exception[1]
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\__init__.py", line 357, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django\apps\config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "D:\Coding\TimeSheet\_OFFICIAL_\InsemiTimeSheet\Project\Infrastructure\InsemiSystem\Hierarchy\models.py", line 3, in <module>
from django.contrib.auth.admin import UserAdmin
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django\contrib\auth\admin.py", line 6, in <module>
from django.contrib.auth.forms import (
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django\contrib\auth\forms.py", line 20, in <module>
UserModel = get_user_model()
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python37\lib\site-packages\django\contrib\auth\__init__.py", line 161, in get_user_model
"AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL
django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'Hierarchy.CustomUser' that has not been installed
I have defined it in my models.py
from django.db import models
from django.contrib.auth.models import (AbstractBaseUser, BaseUserManager)
from django.contrib.auth.admin import UserAdmin
class CustomUser(AbstractBaseUser):
#I proceeded to create the User details here
I also added it correctly as the AUTH_USER_MODEL using -
AUTH_USER_MODEL = 'Hierarchy.CustomUser'

Related

How do I solve a traceback when runing manage.py commands?

I am pretty new to Django and I was just following along witht the tutorial.
I was making a project from https://github.com/justdjango/getting-started-with-django, and after I added users and a superuser, I started to get a Traceback like this:
Traceback (most recent call last):
File "C:\Users\Dell\Desktop\prog\programa\lib\site-packages\django\contrib\auth\__init__.py", line 160, in get_user_model
return django_apps.get_model(settings.AUTH_USER_MODEL, require_ready=False)
File "C:\Users\Dell\Desktop\prog\programa\lib\site-packages\django\apps\registry.py", line 204, in get_model
app_label, model_name = app_label.split('.')
ValueError: not enough values to unpack (expected 2, got 1)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Dell\Desktop\prog\manage.py", line 22, in <module>
main()
File "C:\Users\Dell\Desktop\prog\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\Dell\Desktop\prog\programa\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
utility.execute()
File "C:\Users\Dell\Desktop\prog\programa\lib\site-packages\django\core\management\__init__.py", line 395, in execute
django.setup()
File "C:\Users\Dell\Desktop\prog\programa\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Dell\Desktop\prog\programa\lib\site-packages\django\apps\registry.py", line 122, in populate
app_config.ready()
File "C:\Users\Dell\Desktop\prog\programa\lib\site-packages\django\contrib\admin\apps.py", line 27, in ready
self.module.autodiscover()
File "C:\Users\Dell\Desktop\prog\programa\lib\site-packages\django\contrib\admin\__init__.py", line 24, in autodiscover
autodiscover_modules('admin', register_to=site)
File "C:\Users\Dell\Desktop\prog\programa\lib\site-packages\django\utils\module_loading.py", line 47, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2032.0_x64__qbz5n2kfra8p0\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "C:\Users\Dell\Desktop\prog\programa\lib\site-packages\django\contrib\auth\admin.py", line 6, in <module>
from django.contrib.auth.forms import (
File "C:\Users\Dell\Desktop\prog\programa\lib\site-packages\django\contrib\auth\forms.py", line 21, in <module>
UserModel = get_user_model()
File "C:\Users\Dell\Desktop\prog\programa\lib\site-packages\django\contrib\auth\__init__.py", line 162, in get_user_model
raise ImproperlyConfigured("AUTH_USER_MODEL must be of the form 'app_label.model_name'")
django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL must be of the form 'app_label.model_name'
You forgot to specify the model name in the AUTH_USER_MODEL setting. If you defined a model User in the leads app, you thus set this with:
# settings.py
# app name &downarrow;
AUTH_USER_MODEL = 'leads.User'
# model name &uparrow;

How to solve this django OneToOneField model error?

I'm trying to make a model that needs a relationship of one to one with a feedstock that is used by a plenty of formulas. This is my code:
from django.db import models
from dashboard.models import Formulas, Feedstock
class FeedstockFormulas(models.Model):
ratio = models.FloatField()
feedstock = models.OneToOneField(Feedstock, on_delete=models.CASCADE, default="0")
formulas = models.ForeignKey(Formulas, on_delete=models.CASCADE)
This is the error I'm getting:
Traceback (most recent call last):
File "/home/isaacrpl7/.local/lib/python3.8/site-packages/django/db/models/fields/related.py", line 798, in __init__
to._meta.model_name
AttributeError: module 'dashboard.models.Feedstock' has no attribute '_meta'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/isaacrpl7/.local/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/isaacrpl7/.local/lib/python3.8/site-packages/django/core/management/__init__.py", line 377, in execute
django.setup()
File "/home/isaacrpl7/.local/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/isaacrpl7/.local/lib/python3.8/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/home/isaacrpl7/.local/lib/python3.8/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/mnt/c/Users/isaac/Documents/Github/uniaoracoes/dashboard/models/__init__.py", line 1, in <module>
from .Formulas import Formulas
File "/mnt/c/Users/isaac/Documents/Github/uniaoracoes/dashboard/models/Formulas.py", line 2, in <module>
from dashboard.models import FeedstockFormulas
File "/mnt/c/Users/isaac/Documents/Github/uniaoracoes/dashboard/models/FeedstockFormulas.py", line 4, in <module>
class FeedstockFormulas(models.Model):
File "/mnt/c/Users/isaac/Documents/Github/uniaoracoes/dashboard/models/FeedstockFormulas.py", line 6, in FeedstockFormulas
feedstock = models.OneToOneField(Feedstock, on_delete=models.CASCADE, default="0")
File "/home/isaacrpl7/.local/lib/python3.8/site-packages/django/db/models/fields/related.py", line 1049, in __init__
super().__init__(to, on_delete, to_field=to_field, **kwargs)
File "/home/isaacrpl7/.local/lib/python3.8/site-packages/django/db/models/fields/related.py", line 800, in __init__
assert isinstance(to, str), (
AssertionError: OneToOneField(<module 'dashboard.models.Feedstock' from '/mnt/c/Users/isaac/Documents/Github/uniaoracoes/dashboard/models/Feedstock.py'>) is invalid. First parameter to ForeignKey must be either a model, a model name, or the string 'self'
I can't really solve it, since the first parameter to ForeignKey is already a model...
It looks like this is a by-product of a circular import somewhere.
Try changing to
feedstock = models.OneToOneField("dashboard.Feedstock", on_delete=models.CASCADE, default="0")
formulas = models.ForeignKey("dashboard.Formulas", on_delete=models.CASCADE)

Unable to override both contrib.admin.AdminSite and django.contrib.auth.admin.UserAdmin simultaneously

Using Django 3.1 and Python 3.6, I'm trying to both override the default AdminSite class, and the UserAdmin. I'm trying to combine the examples from two different sections of the documentation:
Overriding the default admin site
Extending the existing User model
Originally I had just the overriden AdminSite class, but then the problem arose when I tried to also override UserAdmin.
Both of these work independently. I can either override AdminSite and get a custom header, or UserAdmin and get my inline showing.
For whatever reason, I run into an import error: ImportError: Module "core.admin" does not define a "CoreCustomAdmin" attribute/class. It looks like a sort of circular dependency, but that's just a guess, as I cannot figure out where/how it's happening.
Stack trace:
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/home/infernous/project_name/.venv/lib/python3.6/site-packages/django/utils/module_loading.py", line 20, in import_string
return getattr(module, class_name)
AttributeError: module 'core.admin' has no attribute 'CoreCustomAdmin'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/infernous/project_name/.venv/lib/python3.6/site-packages/django/utils/module_loading.py", line 44, in autodiscover_modules
if register_to:
File "/home/infernous/project_name/.venv/lib/python3.6/site-packages/django/utils/functional.py", line 240, in inner
self._setup()
File "/home/infernous/project_name/.venv/lib/python3.6/site-packages/django/contrib/admin/sites.py", line 540, in _setup
AdminSiteClass = import_string(apps.get_app_config('admin').default_site)
File "/home/infernous/project_name/.venv/lib/python3.6/site-packages/django/utils/module_loading.py", line 17, in import_string
module = import_module(module_path)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/infernous/project_name/src/core/admin.py", line 2, in <module>
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
File "/home/infernous/project_name/.venv/lib/python3.6/site-packages/django/contrib/auth/admin.py", line 26, in <module>
class GroupAdmin(admin.ModelAdmin):
File "/home/infernous/project_name/.venv/lib/python3.6/site-packages/django/contrib/admin/decorators.py", line 21, in _model_admin_wrapper
if not isinstance(admin_site, AdminSite):
File "/home/infernous/project_name/.venv/lib/python3.6/site-packages/django/utils/functional.py", line 240, in inner
self._setup()
File "/home/infernous/project_name/.venv/lib/python3.6/site-packages/django/contrib/admin/sites.py", line 540, in _setup
AdminSiteClass = import_string(apps.get_app_config('admin').default_site)
File "/home/infernous/project_name/.venv/lib/python3.6/site-packages/django/utils/module_loading.py", line 24, in import_string
) from err
ImportError: Module "core.admin" does not define a "CoreCustomAdmin" attribute/class
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/infernous/project_name/.venv/lib/python3.6/site-packages/django/utils/module_loading.py", line 20, in import_string
return getattr(module, class_name)
AttributeError: module 'core.admin' has no attribute 'CoreCustomAdmin'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/home/infernous/project_name/.venv/lib/python3.6/site-packages/django/utils/autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "/home/infernous/project_name/.venv/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 110, in inner_run
autoreload.raise_last_exception()
File "/home/infernous/project_name/.venv/lib/python3.6/site-packages/django/utils/autoreload.py", line 76, in raise_last_exception
raise _exception[1]
File "/home/infernous/project_name/.venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 357, in execute
autoreload.check_errors(django.setup)()
File "/home/infernous/project_name/.venv/lib/python3.6/site-packages/django/utils/autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "/home/infernous/project_name/.venv/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/infernous/project_name/.venv/lib/python3.6/site-packages/django/apps/registry.py", line 122, in populate
app_config.ready()
File "/home/infernous/project_name/.venv/lib/python3.6/site-packages/django/contrib/admin/apps.py", line 24, in ready
self.module.autodiscover()
File "/home/infernous/project_name/.venv/lib/python3.6/site-packages/django/contrib/admin/__init__.py", line 24, in autodiscover
autodiscover_modules('admin', register_to=site)
File "/home/infernous/project_name/.venv/lib/python3.6/site-packages/django/utils/module_loading.py", line 53, in autodiscover_modules
if register_to:
File "/home/infernous/project_name/.venv/lib/python3.6/site-packages/django/utils/functional.py", line 240, in inner
self._setup()
File "/home/infernous/project_name/.venv/lib/python3.6/site-packages/django/contrib/admin/sites.py", line 540, in _setup
AdminSiteClass = import_string(apps.get_app_config('admin').default_site)
File "/home/infernous/project_name/.venv/lib/python3.6/site-packages/django/utils/module_loading.py", line 17, in import_string
module = import_module(module_path)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/infernous/project_name/src/core/admin.py", line 2, in <module>
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
File "/home/infernous/project_name/.venv/lib/python3.6/site-packages/django/contrib/auth/admin.py", line 26, in <module>
class GroupAdmin(admin.ModelAdmin):
File "/home/infernous/project_name/.venv/lib/python3.6/site-packages/django/contrib/admin/decorators.py", line 21, in _model_admin_wrapper
if not isinstance(admin_site, AdminSite):
File "/home/infernous/project_name/.venv/lib/python3.6/site-packages/django/utils/functional.py", line 240, in inner
self._setup()
File "/home/infernous/project_name/.venv/lib/python3.6/site-packages/django/contrib/admin/sites.py", line 540, in _setup
AdminSiteClass = import_string(apps.get_app_config('admin').default_site)
File "/home/infernous/project_name/.venv/lib/python3.6/site-packages/django/utils/module_loading.py", line 24, in import_string
) from err
ImportError: Module "core.admin" does not define a "CoreCustomAdmin" attribute/class
I do, in fact, have the default admin not loaded (that gives an error anyway).
settings.py:
INSTALLED_APPS = [
...
'core.apps.CoreCustomAdmin',
...
# 'django.contrib.admin', # Commented out
The problem file? Changing the ordering of the imports does nothing, which is expected since it is Python:
core/admin.py:
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from django.contrib.auth.models import User, Group
from allauth.account.models import UserData
class CoreCustomAdmin(admin.AdminSite):
site_header = 'Custom Header'
class UserDataInline(admin.StackedInline):
model = UserData
can_delete = False
class CustomUserAdmin(BaseUserAdmin):
inlines = (UserDataInline,)
admin.site = CoreCustomAdmin()
admin.site.register(User, CustomUserAdmin)
admin.site.register(Group)
The only place where I import core.admin. I have tried change admin.site = CoreCustomAdmin() from core/admin.py to something like customadmin = CoreCustomAdmin() and using that, but it did nothing, naturally.
urls.py
from django.urls import path, include
from core.admin import admin
app_name = 'project_name'
urlpatterns = [
...
path('admin/', admin.site.urls),
]
core/apps.py
from django.apps import AppConfig
from django.contrib.admin.apps import AdminConfig
class CoreConfig(AppConfig):
name = 'core'
class CoreCustomAdmin(AdminConfig):
default_site = 'core.admin.CoreCustomAdmin'
Thanks!
I accidentally fixed it after coming back to the problem 3 weeks later and spending 5 minutes on it. I changed the line in settings.py from
'core.apps.CoreCustomAdmin',
to
'base.apps.AdminConfig',
The reason it's base.apps instead of core.apps is because I'd renamed the app to "base" as per the comment on the question, in an attempt to solve the problem. Had I not done so, it would have been just changing CoreCustomAdmin to AdminConfig.
As far as I can tell, it's achieved the desired effect. It still has both the custom header on the admin site, as well as the inline on the User model edit page.

Error using Textfield and charfield model in Django

I have been trying to use Textfield in class but the suggestions just does not show up. Instead i receive an error in my Cmd console. This was even the case while using CharField.
Below is my code:
from django.db import models
from django.db.models import CharField
from django.db.models import Textfield
from datetime import datetime
class Posts(models.Model):
title = models.CharField(max_length=200)
body = models.TextField()
created_at = models.DateTimeField(default=datetime.now, blank=True)
This is the error i get in my CMD:
Exception in thread django-main-thread:
Traceback (most recent call last):
File "d:\python\python38\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "d:\python\python38\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\USER\Envs\py1\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\USER\Envs\py1\lib\site-packages\django\core\management\commands\runserver.py", line
109, in inner_run
autoreload.raise_last_exception()
File "C:\Users\USER\Envs\py1\lib\site-packages\django\utils\autoreload.py", line 76, in
raise_last_exception
raise _exception[1]
File "C:\Users\USER\Envs\py1\lib\site-packages\django\core\management\__init__.py", line 357, in
execute
autoreload.check_errors(django.setup)()
File "C:\Users\USER\Envs\py1\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\USER\Envs\py1\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\USER\Envs\py1\lib\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "C:\Users\USER\Envs\py1\lib\site-packages\django\apps\config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "d:\python\python38\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "E:\Python\djangoproject\posts\models.py", line 3, in <module>
from django.db.models import Textfield
ImportError: cannot import name 'Textfield' from 'django.db.models' (C:\Users\USER\Envs\py1\lib\site-
packages\django\db\models\__init__.py)
Actually you don't need to import the fields separately, you could use the django.db.models that you have imported earlier.
And the error is produced because you should use TextField with a capital F

Inspectdb error django

I have postgresql db. I want to make reverse engeneering from db by command
python3 manage.py inspectdb > models/models.py
All was ok, but I needed to customize auth. I extends from AbstractBaseUser, and try to reispect, because I was alter fields.Then, I looked up in db, and I saw that django add a pound of tables and I cant reinspect my db. Error:
python3 manage.py inspectdb > models/models.py
super(ForeignObject, self).contribute_to_class(cls, name, private_only=private_only, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/django/db/models/fields/related.py", line 314, in contribute_to_class
lazy_related_operation(resolve_related_class, cls, self.remote_field.model, field=self)
File "/usr/local/lib/python3.4/dist-packages/django/db/models/fields/related.py", line 81, in lazy_related_operation
return apps.lazy_model_operation(partial(function, **kwargs), *model_keys)
File "/usr/local/lib/python3.4/dist-packages/django/db/models/fields/related.py", line 79, in <genexpr>
model_keys = (make_model_tuple(m) for m in models)
File "/usr/local/lib/python3.4/dist-packages/django/db/models/utils.py", line 23, in make_model_tuple
"must be of the form 'app_label.ModelName'." % model
ValueError: Invalid model reference 'models.model.Account'. String model references must be of the form 'app_label.ModelName'.
artem#artem-debian:/usr/finstatement/project$ python3 manage.py inspectdb > models/models.py
ERROR OH NO
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/django/db/models/utils.py", line 14, in make_model_tuple
app_label, model_name = model.split(".")
ValueError: too many values to unpack (expected 2)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 341, in execute
django.setup()
File "/usr/local/lib/python3.4/dist-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.4/dist-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/usr/local/lib/python3.4/dist-packages/django/apps/config.py", line 199, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/usr/local/lib/python3.4/dist-packages/django/contrib/admin/models.py", line 37, in <module>
class LogEntry(models.Model):
File "/usr/local/lib/python3.4/dist-packages/django/db/models/base.py", line 157, in __new__
new_class.add_to_class(obj_name, obj)
File "/usr/local/lib/python3.4/dist-packages/django/db/models/base.py", line 316, in add_to_class
value.contribute_to_class(cls, name)
File "/usr/local/lib/python3.4/dist-packages/django/db/models/fields/related.py", line 700, in contribute_to_class
super(ForeignObject, self).contribute_to_class(cls, name, private_only=private_only, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/django/db/models/fields/related.py", line 314, in contribute_to_class
lazy_related_operation(resolve_related_class, cls, self.remote_field.model, field=self)
File "/usr/local/lib/python3.4/dist-packages/django/db/models/fields/related.py", line 81, in lazy_related_operation
return apps.lazy_model_operation(partial(function, **kwargs), *model_keys)
File "/usr/local/lib/python3.4/dist-packages/django/db/models/fields/related.py", line 79, in <genexpr>
model_keys = (make_model_tuple(m) for m in models)
File "/usr/local/lib/python3.4/dist-packages/django/db/models/utils.py", line 23, in make_model_tuple
"must be of the form 'app_label.ModelName'." % model
ValueError: Invalid model reference 'models.model.Account'. String model references must be of the form 'app_label.ModelName'.
And it delete all models from models/models.py
I have a dumps now, but maybe I can find a better solution than recreate a DB?
Ok, I found I a solution. Need to delete from manage.py
AUTH_USER_MODEL = 'models.models.Account'

Categories