24π
This approach solved my problem using django - version 1.9.5
. Therefore, if you need to run an old Django application with new python check the following approach:
If your are using virtual environment go to: venv/lib/Python3.8/site-packages/django/db/models/base.py
. Then, on the class ModelBase(type):
model add the following code:
(MAKE SURE YOU ADD ONLY THE CODE SPECIFIED)
class ModelBase(type):
"""
Metaclass for all models.
"""
def __new__(cls, name, bases, attrs):
super_new = super(ModelBase, cls).__new__
# Also ensure initialization is only performed for subclasses of Model
# (excluding Model class itself).
parents = [b for b in bases if isinstance(b, ModelBase)]
if not parents:
return super_new(cls, name, bases, attrs)
# Create the class.
module = attrs.pop('__module__')
new_class = super_new(cls, name, bases, {'__module__': module})
# <========== THE CODE BELLOW SHOULD BE ADDED ONLY ======>>
new_attrs = {'__module__': module}
classcell = attrs.pop('__classcell__', None)
if classcell is not None:
new_attrs['__classcell__'] = classcell
new_class = super_new(cls, name, bases, new_attrs)
# <========== THE CODE ABOVE SHOULD BE ADDED ONLY ======>>
# the rest of the class .....
Now, go to the directory that the file manage.py
is located and migrate your application.
Then, python manage.py run
.
Iβve got this answer from this website.
8π
Check your python and django versions. I had the same problem and had to install a previous python with via pyenv.
2π
Occurence
While installing some python package the pipenv
(package manager) downgraded django
version to some 1.0.x
while my python version in virtual env was 3.8.5
.
Solution
Reinstalled django
to latest version 3.2.4
to match latest version of python 3.8.5
.
- Django-registration, template
- Where to instantiate boto s3 client so it is reused during a request?
- What does it mean for an object to be unscriptable?
- Override create method in django rest generics CreateAPIView
- Django: How can I check the last activity time of user if user didn't log out?
1π
I solved similar RuntimeError: __class__ not set defining 'AbstractBaseUser' as ...
error (it was some legacy django 1.9 project) by using virtualenv
and binding it to Python 3.6 installation:
-
Install
virtualenv
:pip3 install virtualenv
-
Download old Python 3.6 and install it with minimal options (only pip checkbox and no "Add to PATH" in options) to some path (I used that django project directory itself,
/my_django_project/python36
for example). -
Create virtual environment, binding it to old python:
cd /my_django_project virtualenv --python=./python36/python.exe venv
-
Activate virtualenv:
.\venv\Scripts\activate
-
Install old
django==1.9
(and other packages when necessary):(venv) pip install django==1.9
-
Launch django backend in activated virtual environment:
(venv) python manage.py runserver
- How to combine django plus gevent the basics?
- Django makemigrations and migrate on heroku server don't create tables
- Why does Django South require a default value when removing a field?
- Uwsgi segmentation fault when serving a django application
-4π
Consider this line
class AbstractBaseUser(models.Model):
RuntimeError: __class__ not set defining 'AbstractBaseUser'as<class'django.contrib.auth.base_user.AbstractBaseUser'>. Was __classcell__ propagated to type.__new__?
- Apps aren't loaded yet exception occurs when using multi-processing in Django
- Create DB Constraint via Django
- Creating UTF-8 JsonResponse in Django
- How can I prevent RuntimeError("Unable to create a new session key.")?